
[Sponsors] 
June 27, 2012, 19:57 
mat2tecplot

#1 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Dear all,
I finally finished and tested a matlab program that will dump data to tecplot binary format directly without using tecio. I'm loving it and here you go. Please see the attached mat2tecplot.m . Simply unzip it and type in matlab command: mat2tecplot It will show you how it works. Wen Long 

November 13, 2012, 17:59 
updated version is attached here

#2 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Just a few updates in readme part. Zone shareing and face connections are still not yet coded. Welcome to the party.


November 13, 2012, 18:38 
update again

#3 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
fix a few typos in readme


January 25, 2013, 15:38 

#4 
New Member
Join Date: May 2012
Location: USA
Posts: 14
Rep Power: 14 
Thanks for posting this code. I am hoping to use it to help validate my Matlab code for my 2D SIMPLE Laminar flow. My Matlab visualization wasn't doing the trick so I'm hoping tecplot will do the trick. Thanks again for the code!


January 31, 2013, 14:50 

#5 
Member
amine
Join Date: Jun 2012
Posts: 65
Rep Power: 14 
Hello CFD Friends hope ur doing well
i didnt understand how it does work!!!could u help me out please??? Thank you so much 

January 31, 2013, 15:04 

#6 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
a) Just download it, unzip it to a folder
b) open matlab c) cd folder_where_the_mat2tecplot.m_file_is d) help mat2tecplot 

February 1, 2013, 20:00 

#7 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Just correct a few typos in readme.


February 4, 2013, 13:54 

#8 
New Member
Join Date: May 2012
Location: USA
Posts: 14
Rep Power: 14 
After reading through the mat2tecplot.m documentation, this is what I did in order to export my matlab data into a readable Tecplot file. Hope this will help any other users out there that aren't quite using it right. This is just my interpretation of Wen Long's code; all credit must be given to him for writing it.
1. You must keep the mat2tecplot.m in the same directory as your other files as your main program will call mat2tecplot.m (should be selfexplanatory but you know never know). 2. In your program, you must call mat2tecplot.m and specify what data you are transferring. 3. Following the examples given in the documentation (I followed example 3 I believe), you can change a few lines of code to reflect which data you want to export. My code is as follows. function name(inputs) tdata=[]; tdata.Nvar=6; tdata.varnames={'x','y','z','u','v','p_new'}; tdata.surfaces(1).zonename='mysurface zone'; tdata.surfaces(1).x=x; tdata.surfaces(1).y=y; tdata.surfaces(1).v(1,:,: )=u; tdata.surfaces(1).v(2,:,: )=v; tdata.surfaces(1).v(3,:,: )=p_new; mat2tecplot(tdata,'SIMPLE Results.plt') end You have to make sure that the value specified in tdata.Nvar is equal to the number of variables you place in tdata.varnames. I specified 6 variables and then had 6 names given. I have 2D flow (x,y,z=0) and want my data for u and v momentum and pressure exported. "tdata.surfaces(1).x= " is used to specify your domain. In the example, coordinates are given for x,y,z; in my code; i simply set the .x value equal to my xvalues on my defined mesh. The same was done for the yvalues. if you specify nothing (as with z), it is assumed 0. The "tdata.surfaces(1).v(1,:,: )= " code specifies which data you want displayed as a result. i set it equal to my u momentum. To add multiple data to the same file, you change the .v(1,:,: ) to .v(2,:,: ) etc... for as many different data sets as you like. I had 3 data sets (u,v,pressure) so I have 3 lines. Finally, the last line in the code calls mat2tecplot using the values you have specified and outputs an easily readable tecplot input file (called 'SIMPLE Results'). My contour plots for momentum and pressure look much better than they did on matlab plus you now have the flexibility of using tecplot to manipulate your visualization axis, contour # etc... You just have to add a few lines of code to your matlab program and the mat2tecplot.m does all the work for you. Now if I could just figure out how to transfer my streamline data I'd be all set  anyone have any tips? 

February 5, 2013, 01:17 

#9 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Thank you for the nice explanation and I'm glad it works for you.
Two cents: 1)You can have as many zones as you want, as long as all the zones have same number of variables and same variable names. If you want to make a movie, you can put the first time frame in surfaces(1), and 2nd time frame in surfaces(2) etc and give solutiontime to each of them, e.g. surfaces(1).solutiontime=0.0, surfaces(2).solutiontime=1.0, ... Then you will be able to move from one zone to another in tecplot and use &(solutiontime) in label texts to label the time. Alternatively, instead of using solutiontime, you can use strandID 2)x,y,z are variables for 3D system, if you have only 2D dataset, then one of them can be treated as a dependent variable, and the other two as independent variable, for example z=z(x,y). (which one is dependent variable is based on order of the surface,line, FEsurface etc). In this case, x, y are called the coordinate variables, and z is a function defined on x, y coordinates, and z can be named whatever you want in varnames. Similarly, x, y do not always mean Cartesian coordinates, x, y can be polar coordinate, for example tdata.surfaces.x=rho; tdata.surfaces.y=theta; tdata.surfaces.z=T; tdata.varnames={'rho','theta','T'} In this case, (x,y) is (rho, theta), i.e. polar coordinate ,and z is temperature defined on (rho,theta), e.g. T on a disk. If your coordinates are on (y,z) plane, then x is treated as a dependent variable, such as tdata.surfaces.x=T, tdata.surfaces.y=y, tdata.surfaces.z=z, which means T=T(y,z), in this case you have to give the order (i.e. orientation) of the surface, that is tdata.surfaces.order=1 . In this case, x can be one of your results you want to plot, and the rest of them should be in v(ivar,:,: ). You could also give no x values at all, and put all dependent variables in v(ivar,:,: ), except that in this case x will be treated as zeros and you have to account x in the number of variables. By default, surface order is assumed to be 3, i.e. z=z(x,y). Similarly, for lines, if you have only 1D data, i.e. XY plots, i.e. y=y(x), then y,z,v etc are all going to be x's function. This is handled similarly by lines.order parameter. By default, it is assumed to be 3D lines, i.e. v=v(x,y,z) with x,y,z all being oneD array storing (x,y,z) coordinates of a series of points on the line. If you have x,z,v as function of y, then the order must be 2, i.e. you are using y as the coordinate only. 3) If you have only one zone for a type, e.g. only one surface zone, you can use surfaces.x instead of surfaces(1).x etc, like in 2) 4)for streamlines, once you have x,y, u, v in the zone, tecplot can generate streamlines for you. If you insist using your own streamline data, e.g. streamline as a 2D curve defined by connecting multiple points, you can use the line zones in addition to the surface zones. e.g. lines(1).x=[x coordinates of the points on a stream line], lines(1).y=......, and use lines(1).z or lines(1).v(ivar,: ) for colors of the streamline or variables on the streamline points, e.g. density on the streamline. And then repeat for lines(2).x, lines(2).y, lines(2).z, lines(2).v(ivar,: ) etc for the second streamline. 5)dimension size of v(ivar,:,:,: ) is dependent on whether the variable ivar is defined on all coordinate points or the center of an element. If at the center of element, e.g. for x,y coordinates to be 3x4, then you will only have 2x3 points to give v values for variable ivar, i.e. (31)x(41), in this case you have to specify varloc=1 for ivar'th variable in v. By default, it is assumed to be zero, i.e. on coordinate points. 6) mat2tecplot.m does NOT have to be in the same directory of your main program or data if you have added the folder name to PATH e.g. by executing addpath('C:\directory\name\of\mat2tecplot.m\','end'); Normally, people put these kind of PATH setups for matlab in startup.m, please search for matlab startup.m configuration. As long as the program is in PATH, matlab knows where to find it. Last edited by wenlong; February 6, 2013 at 11:02. 

February 28, 2013, 17:13 

#10 
New Member
Join Date: Feb 2013
Posts: 4
Rep Power: 13 
Thanks so much, it works very well for my cases with tdata.cubes.


March 1, 2013, 08:46 

#11  
Member
amine
Join Date: Jun 2012
Posts: 65
Rep Power: 14 
Quote:
1/plz tell me the different steps how to do it(export contours from matlab to tecplot) shortly plz 2/i am working on CFD problem ,i wanna export matlab data and fluent 6.3 data(contours of stream functions) to same frame and plot them together in order to compare the isolines Best wishes Thank u in advance 

March 1, 2013, 11:09 

#12  
New Member
Join Date: Feb 2013
Posts: 4
Rep Power: 13 
Quote:
I have a DNS database which includes the coordinate matrices x, y, z as well as the velocity fields u, v and w. All matrices have the same size of nl*nc*ns. Then I use Matlab to compute some new parameters like swirling rate. At the end of my own script I use mat2tecplot.m to convert mat files to PLT format. Here is what I put at the end of my script: PLTout = strcat(outputAddress,PLTout_name); %The output name and address tdata=[]; tdata.Nvar=7; %number of variables tdata.vformat = 2*ones(1,tdata.Nvar); %Double precision for each variable (optional) tdata.varnames={'x','y','z','u','v','w','Lambda'}; tdata.cubes(1).zonename=eval('PLTout_name'); %any name tdata.cubes(1).x=x(nl*nc*ns); tdata.cubes(1).y=y(nl*nc*ns); tdata.cubes(1).z=z(nl*nc*ns); tdata.cubes(1).v(1,:,:,: )=u(nl*nc*ns); tdata.cubes(1).v(2,:,:,: )=v(nl*nc*ns); tdata.cubes(1).v(3,:,:,: )=w(nl*nc*ns); tdata.cubes(1).v(4,:,:,: )=lambda(nl*nc*ns); mat2tecplot(tdata,eval('PLTout')) I can easily visulize this PLT file in Tecplot Hope this helps 

March 4, 2013, 08:37 

#13  
Member
amine
Join Date: Jun 2012
Posts: 65
Rep Power: 14 
Quote:
Thank You So Much , i will try it be in touch plz have a nice day 

September 24, 2013, 21:36 
Re : mat2tecplot.m

#14 
New Member
mn1729
Join Date: Sep 2013
Posts: 1
Rep Power: 0 
Thanks a lot for this post. It was extremely useful. It is really hard to figure out the binary format from the tecplot manual.


December 10, 2013, 09:12 
thanks

#15 
New Member
Marita torregrosa
Join Date: Dec 2013
Posts: 1
Rep Power: 0 
I used your code for converting a set of images (ij ordered) into a volume (ijk) avoiding interpolation... I am quite new at CFD, and your code was very easy to implement. Thank you very much!


February 7, 2014, 07:05 
Have problem to add the aux data.

#16 
New Member
trim
Join Date: Feb 2014
Posts: 1
Rep Power: 0 
Hi wenlong:
I have problem to add the aux data to the FE surface. with out the add aux lines, the tecplot can open the file, However, when I add the aux data to the data zone, the file cannot be opened. Thanks. tdata=[]; tdata.Nvar=4; tdata.varnames={'x','y','z','T'}; tdata.FEsurfaces(1).zonename='my surface zone'; tdata.FEsurfaces(1).x=[1,2,2.5]; %totally 5 nodes tdata.FEsurfaces(1).y=[1,3,1]; tdata.FEsurfaces(1).order=3; %surface defiend on (y,z) coord tdata.FEsurfaces(1).e2n=[1,2,3];%3 elements(row) %each with 3 node numbers %(each row has 3 columns) tdata.FEsurfaces(1).v(1,=[10,20,30]; %temperature on 5 nodes %only one row (temperatue) %(the row has 5 columns) tdata.FEsurfaces(1).auxname{1} = 'Time'; tdata.FEsurfaces(1).auxval{1} = 'TT'; mat2tecplot(tdata,'myFEsurface_yz.plt') 

February 12, 2014, 07:12 

#17 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Thanks I will take a look and get back to u


March 4, 2014, 18:10 

#18 
New Member
Italy
Join Date: Mar 2014
Posts: 1
Rep Power: 0 
Hi
I'm new in using TecPlot and I need it for a university project. I downloaded the mat2tecplot.m code but I couldn't manage by myself. My problem is the following: I have a cube represented by a matrix 36X36X36, and for each cell center I know exactly the velocity of that cell(vx,vy,vz). The velocity field is represented by 3 different matrix, one for vx (36X36X36) same size for vy, vz. I tried to use the example 11, but when I load in Tecplot and I try to interpolate an error window appears and says that the interpolation can be done only for nodal value. How could I solve this problem? Thank you, any help is really appreciated 

March 21, 2014, 18:31 

#19 
New Member
wen long
Join Date: May 2012
Posts: 29
Rep Power: 14 
Hi ciccio
Cubes are simple, because you have 36x36x36 for the cubes vertex points and your u,v,w are on the center of each cube, that means you should supply u,v,w as 35x35x35 arrays instead. Here is an example code  tdata=[]; tdata.Nvar=6; tdata.varnames={'x','y','z','u','v','w'}; tdata.cubes(1).zonename='my IJK volume cubes zone'; x=(1:1:36); y=(1:1:36); z=z(1:1:36); [x3d,y3d,z3d]=meshgrid(x,y,z); tdata.cubes(1).x=x3d; tdata.cubes(1).y=y3d; tdata.cubes(1).z=z3d; u3d=repmat(random('norm',0.1,0.2,35),[1,1,35]); v3d=repmat(random('norm',0.1,0.2,35),[1,1,35]); w3d=repmat(random('norm',0.1,0.2,35),[1,1,35]); tdata.cubes(1).v(1,:,:,: )=u3d; tdata.cubes(1).v(2,:,:,: )=v3d; tdata.cubes(1).v(3,:,:,: )=w3d; tdata.cubes(1).varloc=1; mat2tecplot(tdata,'mycube_IJK_volume_cellcenter.pl t')  Then you can view the plot in tecplot, and attached pic is what I got. Wen 

June 3, 2014, 15:37 
mat2tecplot.m

#20 
New Member
nacera
Join Date: Feb 2014
Posts: 4
Rep Power: 12 
hello
I have a problem when I load data file in tecplot, the file is generate with matlab with mat2tecplot.m . I get this message: Binary file version newer than tecplot version. Upgrade Tecplot or use an older preplot to produce the data 

Thread Tools  Search this Thread 
Display Modes  

