How to use contourf with 1D data
Show older comments
Hello,
I'm using the method of characteristics to solve 2D supersonic flows inside a nozzle. The discrete solution is thus computed on n different points inside the nozzle.
At the end of the process, I get :
x % a 1D vector (1 x n) of the x coordinates of the points where a solution is computed
y % a 1D vector (1 x n) of the y coordinates of the points where a solution is computed
M % a 1D vector (1 x n) of the Mach number of the flow at the corresponding [x,y] points
I'd like to depict the solution I have on a 2D plot using contourf to obtain something like that :

My problem is that I don't know how to use meshgrid or reshape to do so.
I also would like to use quiver to show the flow direction, but I logically face the same problem...
Can you help me ?
Thanks a lot :-)
Answers (1)
darova
on 9 Apr 2020
Use linspace and meshgrid to create regular mesh
xx = linspace(min(xdata),max(xdata),20);
yy = linspace(min(ydata),max(ydata),20);
[X,Y] = meshgrid(xx,yy);

Use griddata to calculate value at each grid point
Z = griddata(xdata,ydata,zdata,X,Y);

And finally use contour to create contour

3 Comments
Antoine Laterre
on 10 Apr 2020
Lalit Duseja
on 29 Jun 2022
Antoine Laterre can you share the code or guide me how you did this. I have a smilar problem. The diameter varies along x and I have to plot the temperature contours.
Antoine Laterre
on 29 Jun 2022
Edited: Walter Roberson
on 29 Jun 2022
Categories
Find more on Gas Dynamics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!