Why do I keep getting this error? "Error using surf Z must be a matrix, not a scalar or vector."
Show older comments
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)
xlabel('0 (degrees)'); ylabel('Force (lbs)'); zlabel('Moment (lbs-ft)')
1 Comment
Adam Danz
on 11 Apr 2023
Note duplicate
Answers (1)
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)
size(j)
size(Moment)
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!