How to make contour plot of two matrices in MATLAB?

6 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2022-11-27
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 2022-11-27
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.

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2022-11-27
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 个评论
Araz Garaz
Araz Garaz 2022-11-27
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by