How to make contour plot of two matrices in MATLAB?

6 ビュー (過去 30 日間)
Araz Garaz
Araz Garaz 2022 年 11 月 27 日
コメント済み: Star Strider 2022 年 11 月 27 日
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.
Star Strider
Star Strider 2022 年 11 月 27 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-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