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