Error: Z must be a matrix, not a scalar or vector
2 ビュー (過去 30 日間)
古いコメントを表示
Hey, so I am trying to plot this but I get this error. I'm fairly new to MATLAB so I dont know how to fix this issue. Thank you!
close all;
A1 = csvread('Circle6inch copy');
A2 = csvread('Circle12inchCopy');
A3 = csvread('Circle18inchCopy');
r = [6,12,18];
x = [cos(A1(:,1))*r(1); cos(A2(:,1))*r(2); cos(A3(:,1))*r(3)] ;
y = [sin(A1(:,1))*r(1); sin(A2(:,1))*r(2); sin(A3(:,1))*r(3)] ;
a = [A1(:,2); A2(:,2); A3(:,2)];
z = meshgrid(x,y);
n = length(x);
m = length(y);
for i = 1 : n
for j = 1 : m
z(i,j) = a(j);
end
end
[ii,ii] = unique(z','rows','first');
out = z(:,sort(ii));
z = out;
surf(x,y,a);
0 件のコメント
回答 (1 件)
jean claude
2017 年 12 月 10 日
2 件のコメント
Walter Roberson
2017 年 12 月 10 日
With three outputs, meshgrid() is going to output 3D arrays, but the z input to meshgrid needs to be 2D.
Aside from that, your code is dubious. Your lines
for i = 1 : n
for j = 1 : m
z(i,j) = a(j);
end
end
set all rows to have the same content. For example, z(1,5) = a(5), but also z(2,5) = a(5), z(3,5) = a(5) and so on. There does not appear to be much point in that.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!