I am trying to create a surface plot with nested loops and am getting the error "Z must be a matrix, not a scalar or vector."

3 Ansichten (letzte 30 Tage)
clear all
n=1;
for ii = 1:10;
for jj = 1:10;
x(n) = ii;
y(n) = jj;
z(n) = ii+jj;
n = n+1;
end
end
surf(x,y,z)

Akzeptierte Antwort

G A
G A am 22 Apr. 2019
Bearbeitet: G A am 24 Apr. 2019
Try something like the following (z must be a matrix):
for m = 1:10
x(m) = m;
for n = 1:10
y(n) = n;
z(m,n) = n+m;
end
end
surf(x,y,z)

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by