Error: Z must be a matrix, not a scalar or vector
조회 수: 3 (최근 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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!