Error using / Matrix dimensions must agree

조회 수: 2 (최근 30일)
Jose Miguel Araya Martinez
Jose Miguel Araya Martinez 2022년 6월 28일
편집: Voss 2022년 6월 28일
My script is this:
r=linspace(-180,180,360);
t=linspace(-180,180,360);
[R,T]=meshgrid(r,t);
phi_=6*r*cos(1+5^2/R.^2)-T;
contour(R,T,phi_)
but matlab throws the following error: Error using / Matrix dimensions must agree.
What am i doing wrong?

채택된 답변

Voss
Voss 2022년 6월 28일
Use ./
r=linspace(-180,180,360);
t=linspace(-180,180,360);
[R,T]=meshgrid(r,t);
% phi_=6*r*cos(1+5^2/R.^2)-T;
phi_=6*r*cos(1+5^2./R.^2)-T;
contour(R,T,phi_)
  댓글 수: 2
Jose Miguel Araya Martinez
Jose Miguel Araya Martinez 2022년 6월 28일
Thanks!
Voss
Voss 2022년 6월 28일
편집: Voss 2022년 6월 28일
You're welcome!
As @Star Strider points out, you probably intend to use .* as well, but using / instead of ./ is what caused the error.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by