How to make contour plot of two matrices in MATLAB?

6 visualizaciones (últimos 30 días)
Araz Garaz
Araz Garaz el 27 de Nov. de 2022
Comentada: Star Strider el 27 de Nov. de 2022
I have two data files (Data_file1 and Data_file2) to do a comparison on.
Data files both are matrices with 1 row and 55 columns, which represent 55 points. The points are very similar in value, So plotting them as points wouldn't give a good figure for demonstrating differences. This is why I want to plot each point as a contour.
Here is the code I generated, it technically should work, but somehow it doesn't. Can anyone spot any error that I can't see?
figure;
sm=smithplot(gca);
hold on
NumPowCon=3;
x = linspace(-1,1,55)';
y = linspace(-1,1,55)';
[X,Y] = meshgrid(linspace(min(x),max(x)),linspace(min(y),max(y)));
F = TriScatteredInterp(x,y,Data_file1);
Z = F(X,Y);
contour(X,Y,Z,NumPowCon,'r-')
F = TriScatteredInterp(x,y,Data_file2);
Z = F(X,Y);
contour(X,Y,Z,NumPowCon,'b--')
  2 comentarios
Walter Roberson
Walter Roberson el 27 de Nov. de 2022
We do not have your data so we cannot test your code to see what "doesn't work" means to you.
I notice you are not using subplot() or tiled layout or figure() or hold on so the second contour might erase the first.
Araz Garaz
Araz Garaz el 27 de Nov. de 2022
Thanks for the comment. But it stops at the first contour ploting. The error is 'Xdata' and YData' must be equal the number of columns and rows in 'ZData'. I will add the data files to test the code if you can.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 27 de Nov. de 2022
Data files both are matrices with 1 row and 55 columns, which represent 55 points.
They are vectors by definition, and it is not possible to plot a contour of a vector.
You could vertically concatenate the two row vectors to create a (2x55) matrix and then take the contour of that. I am not certain how meaningful that would be.
It would be necessary to have the vectors to work with in order to determine if it would be possible to do anything with them. For example, if they are ‘z’ vectors, do they have corresponding ‘x’ and ‘y’ vectors that could indicate that they are actually gridded and so could be reshaped to each create a surface?
.
  8 comentarios
Araz Garaz
Araz Garaz el 27 de Nov. de 2022
Oh I hate windows too but not brave enough to shift to Linux. And yes you are right those dash-dot lines were only to indicate differences. You did a great job there, that's exactly what I was trying to do for hours, thank you so much.
Star Strider
Star Strider el 27 de Nov. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by