Error Messages, dimension and plot2cart (Matlab)

조회 수: 1 (최근 30일)
John Smith
John Smith 2014년 10월 6일
댓글: Star Strider 2014년 10월 6일
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

답변 (1개)

Star Strider
Star Strider 2014년 10월 6일
편집: Star Strider 2014년 10월 6일
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
John Smith
John Smith 2014년 10월 6일
Now the errors are - "Error using mesh (line 76) Z must be a matrix, not a scalar or vector
Error in SurfPlotQ1 (line 29) mesh(x,y,w);" and i know its meant to look like this http://i.imgur.com/iz74iV8.jpg?1
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(linspace(0,2*pi,1));
w=meshgrid(linspace(0,rd,1));
r=meshgrid(linspace(0,rd,1));
[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;
surf(x,y,w);
colorbar
end
Star Strider
Star Strider 2014년 10월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by