Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error: Matrix dimensions must agree

조회 수: 1 (최근 30일)
Marcello DeMiranda
Marcello DeMiranda 2020년 4월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
I input this code but it gives me an error mesage for line 9>> h=A.*(x.^m)
ws=[2 4 6];
m=2/3;
A=0.067*(ws.^.44);
x=[0:1:200]
h=A.*(x.^m);
plot(x,h)
set(gca, 'Ydir','reverse');
  댓글 수: 1
Sriram Tadavarty
Sriram Tadavarty 2020년 4월 27일
It rises because x and A are not compatible. To figure out what the compatible matrices are, have a look here.
Hope this helps.

답변 (1개)

Sriram Tadavarty
Sriram Tadavarty 2020년 4월 27일
편집: Sriram Tadavarty 2020년 4월 27일
Hi Marcello,
Here is what happens, in your code. Place the annotations to help you understand.
ws=[2 4 6]; % w is a 1 x 3 matrix
m=2/3; % m is a scalar 1 x 1
A=0.067*(ws.^.44); % A is a 1 x 3 matrix, since ws is 1 x 3
x=[0:1:200] % x is 1 x 201 matrix
h=A.*(x.^m); % Here is the issue, you are trying to have multiplication with (1 x 3)*(1*201)
%% So, to solve this, use make the minor modification
%% h = A'.*(x.^m); % Now you will get 3 x 201, as h value, making them all plotted in output
plot(x,h)
set(gca, 'Ydir','reverse');

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by