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
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.
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!