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 次查看(过去 30 天)
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)

采纳的回答

G A
G A 2019-4-22
编辑:G A 2019-4-24
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by