I am trying to plot my code using meshgrid command for three variables but I receive an error message
1 次查看(过去 30 天)
显示 更早的评论
F = [-40:20:40];
x = linspace(0.1,0.8,length(F));
y = linspace(0.1,0.4,length(F));
sigma_p = @(x,y) F./(.8.*x.*y);
sigma_mx = @(x,y) (F.*y)./(1./12.*(x).*(y).^3);
sigma_my = @(x,y) (F.*x)./(1./12.*(y).*(x).^3);
sigma_net = @(x,y) sigma_p(x,y) + sigma_mx(x,y) + sigma_my(x,y);
figure
plot3(x, y, sigma_net(x,y))
[X,Y] = meshgrid(x,y);
Z = sigma_net(X,Y)
mesh(X,Y,Z)
2 个评论
回答(1 个)
Walter Roberson
2016-9-8
The error message is
Error using ./
Matrix dimensions must agree.
Error in @(x,y)F./(.8.*x.*y)
Error in @(x,y)sigma_p(x,y)+sigma_mx(x,y)+sigma_my(x,y)
You carefully created x and y to be the same length as F, but you are calling with X and Y which is a 2D square grid, and that 2D grid is not the same size as F.
Solution:
sigma_p = @(x,y) repmat(F, size(x,1), 1) ./ (.8.*x.*y);
sigma_mx = @(x,y) (repmat(F, size(x,1), 1) .*y)./(1./12.*(x).*(y).^3);
sigma_my = @(x,y) (repmat(F, size(x,1), 1).*x)./(1./12.*(y).*(x).^3);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!