CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Main CFD Forum (
-   -   Visualization using Matlab (

Chan Keen Ian November 9, 2001 19:25

Visualization using Matlab

I have just started using Matlab as a tool for plotting results generated by a CFD code written in Fortran.

May I know if anyone has scripts for generating contour plots of quantities like Mach number, pressure and so on? Please advice as to how the external data file generated by the CFD code should structure the flow quantities.

Thanks very much,

Chan K I

Paul November 9, 2001 23:21

Re: Visualization using Matlab
Matlab has enormous online documents for the plotting of quiver(velocity vector), contours and other things.

I have some examples if you need them.

ryan November 10, 2001 04:07

Re: Visualization using Matlab

Could you send the matlab examples to me ?

Many thanks..

Junseok Kim November 10, 2001 07:34

Re: Visualization using Matlab
You can use help command at matlab, type

>> help contour

CONTOUR Contour plot.

CONTOUR(Z) is a contour plot of matrix Z treating the values in Z

as heights above a plane. A contour plot are the level curves

of Z for some values V. The values V are chosen automatically.

CONTOUR(X,Y,Z) X and Y specify the (x,y) coordinates of the

surface as for SURF.

CONTOUR(Z,N) and CONTOUR(X,Y,Z,N) draw N contour lines,

overriding the automatic value.

CONTOUR(Z,V) and CONTOUR(X,Y,Z,V) draw LENGTH(V) contour lines

at the values specified in vector V. Use CONTOUR(Z,[v v]) or

CONTOUR(X,Y,Z,[v v]) to compute a single contour at the level v.

[C,H] = CONTOUR(...) returns contour matrix C as described in

CONTOURC and a column vector H of handles to LINE or PATCH

objects, one handle per line. Both of these can be used as

input to CLABEL. The UserData property of each object contains the

height value for each contour.

The contours are normally colored based on the current colormap

and are drawn as PATCH objects. You can override this behavior

with the syntax CONTOUR(...,'LINESPEC') to draw the contours as

LINE objects with the color and linetype specified.

Uses code by R. Pawlowicz to handle parametric surfaces and

inline contour labels.


[c,h] = contour(peaks); clabel(c,h), colorbar


If you want to know more details, just ask me.


Chan Keen Ian November 10, 2001 09:13

Re: Visualization using Matlab

Thanks very much for the advice.

Paul: Would it be OK to send me examples of Matlab contour plotting?

Suppose I had a 3-D H-grid of turbomachinery blade passage, does Matlab have any features to plot and visualize the grid?


dia November 10, 2001 11:47

Re: Visualization using Matlab
would you please e-mail me your examples.

thanks in advance.

yfyap November 10, 2001 21:08

Re: Visualization using Matlab
dear Kim, how do we plot the velocity vetors for, let's say, a two dimensional plot, given the x and y of the velocity components are known? if these data is in text file, then, is it possible to import them into matlab? thanks. regards, yfyap

Junseok Kim November 10, 2001 21:21

Re: Visualization using Matlab
Okay, first of all, you can check quiver command at matlab.

>> help quiver

And about the your question,

you can save velocity files such as u and v,

for example, save u velocity field in a file name


and file content is

A=[1 2 3 4 5 6 7 8 9];

and in another file, say v.m

put contents like this

B=[1 3 2 5 7 6 7 9 8];

Then, surely these files are on the working directory. There are two ways which you can import these data by typing
:> u

and then

>> v

then you can check they are loaded or not by typing

>> whos

you will see

>> u
:> v
:> whos Name Size Bytes Class

A 3x3 72 double array B 3x3 72 double array

Grand total is 18 elements using 144 bytes

Now use quiver command, like this

>> quiver(A,B)

And the other way is make another file, and put above commands in that file, and run that file.


Junseok Kim November 10, 2001 21:24

A=[1 2 3 4 5 6 7 8 9]; B=[1 3 2 5 7 6 7 9 8];

These should be

A=[1 2 3; 4 5 6; 7 8 9]; B=[1 3 2; 5 7 6; 7 9 8];

yfyap November 11, 2001 09:41

Re: p.s.
thanks a lot, got the plot already. for contour plot, i have tried the following, but the contour line won't appear. note z is the height
: x=[ elements of x] y=[ elements of y] z=[ elements of z] contour(x,y,z)

thanks agian. regards, yfyap

Junseok Kim November 11, 2001 09:51

Re: p.s.
The basic idea is you should use matrix not vector for height z on x and y coordinate,


x=[1 2 3 4 5]; y=[1 2 3 4 5];

z=[5 2 3 8 9; 1 3 4 12 4;8 8 6 5 5; 6 98 5 8 9; 86 0 75 98 7];


and try contourf, it is cool.


pran November 13, 2001 13:03

Re: Visualization using Matlab
I 've developed a code for solving 3 D free convection in box and written in fortran. Three dimensional plotting (temperature, pressure and velocity vectors) are generated by using Matlab. If you're interested, I'll send you my codes (*.for & *.m) for you.

Chan Keen Ian November 13, 2001 15:55

Re: Visualization using Matlab
Hi Pran,

Yes, I'm interested in your codes. May I have a copy of the fortran and matlab codes?

Thanks very much, Chan K I

Nassar November 29, 2001 15:15

Re: Visualization using Matlab

Could you send the matlab examples to me ?

Many thanks..

sixfor December 30, 2010 08:39

Hi could you send me the examples, i have no idea where to start


All times are GMT -4. The time now is 23:37.