Error Messages, dimension and plot2cart (Matlab)
Afficher commentaires plus anciens
Hi the following script gives back the errors.But im not sure why
"Error using .* Matrix dimensions must agree.
Error in pol2cart (line 22) x = r.*cos(th);
Error in SurfPlotQ1 (line 18) [x,y]= pol2cart(th,r);"
function graph=plot(c,P,rd,E,t,nu,K,w,y,r,th) ;
c=15;
P=15;
rd=15;
E=18*10^6;
t=0.08;
nu=0.3;
th=meshgrid(0:0.1:2.*pi);
w=meshgrid(0:0.1:rd);
r=meshgrid(0:0.1:rd);
[x,y]= pol2cart(th,r);
K= (E*t^3)/(12*(1-nu^2));
w=((P.*rd.^4)./(64.*K)).*(1-(r./rd).^2).^2+c;
mesh(x,y,w);
colorbar
end
Réponses (1)
Star Strider
le 6 Oct 2014
Modifié(e) : Star Strider
le 6 Oct 2014
0 votes
Use the linspace function to generate the arguments to meshgrid to calculate ‘th’, ‘w’, and ‘r’. That way you can specify all of them to have the same lengths. That will avoid the error you’re getting.
4 commentaires
John Smith
le 6 Oct 2014
Star Strider
le 6 Oct 2014
My pleasure!
You can do linspace outside meshgrid or inside it. It’s all the same to the computer — neither is more efficient. This should work:
th=meshgrid(linspace(0,2*pi,250));
The choice of 250 is arbitrary. Just be sure it’s the same value for all three variables and you won’t get the ‘matrix dimensions must agree’ error. (You don’t want them arguing in any event!)
John Smith
le 6 Oct 2014
Star Strider
le 6 Oct 2014
The third argument to linspace is the length of the vector you want it to create. You’ve asked it to create a scalar with a lenght of 1, and it did!
Change the linspace calls to:
th=meshgrid(linspace(0,2*pi,100));
w=meshgrid(linspace(0,rd,100));
r=meshgrid(linspace(0,rd,100));
and it works.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!