Error: Z must be a matrix, not a scalar or vector
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
jean claude
am 10 Dez. 2017
2 Kommentare
Walter Roberson
am 10 Dez. 2017
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.
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!