필터 지우기
필터 지우기

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 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