Why do I keep getting this error? "Error using surf Z must be a matrix, not a scalar or vector."

2 views (last 30 days)
Moment=zeros(); ki=pi/180; kinc=pi/180; kf=pi; ji=5; jinc=5; jf=100;
for k=ki:kinc:kf
for j=ji:jinc:jf
h=sin(k);
g= cos(k);
Moment (j/jinc,:) = 1800 + j * h * 39 + j * g * 6;
end
end
%k is theta j is force
[k,j] = meshgrid(ki:kinc:kf,ji:jinc:jf);
figure
surf(k,j,Moment)
Error using surf
Z must be a matrix, not a scalar or vector.
xlabel('0 (degrees)'); ylabel('Force (lbs)'); zlabel('Moment (lbs-ft)')

Answers (1)

the cyclist
the cyclist on 11 Apr 2023
At the risk of stating the obvious, you keep getting that error because Moment is a vector, but it needs to be a matrix.
In your case, it needs to be a 20*180 matrix.
Moment=zeros(); ki=pi/180; kinc=pi/180; kf=pi; ji=5; jinc=5; jf=100;
for k=ki:kinc:kf
for j=ji:jinc:jf
h=sin(k);
g= cos(k);
Moment (j/jinc,:) = 1800 + j * h * 39 + j * g * 6;
end
end
%k is theta j is force
[k,j] = meshgrid(ki:kinc:kf,ji:jinc:jf);
size(k)
ans = 1×2
20 180
size(j)
ans = 1×2
20 180
size(Moment)
ans = 1×2
20 1

Categories

Find more on Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!