Using Contour to plot different range data.

1 回表示 (過去 30 日間)
Katarina
Katarina 2013 年 3 月 18 日
コメント済み: Walter Roberson 2016 年 7 月 14 日
For the past 2 hours I am trying to plot my x,y,z data using contour and even after reading examples from MATLAB I am still at the same place. Just for learning purposes I am using dummy data that I have created shown below:
x=1:0.5:20;
y=1:0.5:10;
z=zeros(39,19);
for i=1:1:39
for j=1:1:19
z_value=x(j)+y(j)^2-2*x(i);
z(i,j)=z_value;
end
end
for i=1:1:38
for j=1:1:19
plot3 (x(i),y(j),z(i,j),'ro-')
hold on
end
end
While I am good with plotting it all in 3D, I would like to plot contours however, whenever I try to plot contour(x,y,z) it gives me following message:
*******************************
Error using contour (line 81)
The size of X must match the size of Z or the
number of columns of Z.
Error in test (line 23)
contour (x,y,z)
*******************************
The size of X and Y do match Z! So I am not sure what I am missing. If I cannot use contour, can you please suggest another method in order to obtain similar effect graphing tool?
Thank you for your time.

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 18 日
length(x) matches the number of rows in z, but it needs to match the number of columns in z.
Try
contour(x, y, z.')
  3 件のコメント
McWoz
McWoz 2016 年 7 月 14 日
So, I have changed my X vector to match the columns of Z, but I am still getting this error... is there a bug?
Walter Roberson
Walter Roberson 2016 年 7 月 14 日
McWoz, what is size(x), size(y), size(z) for you?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by