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