Info

This question is closed. Reopen it to edit or answer.

Error: Matrix dimensions must agree

1 view (last 30 days)
Marcello DeMiranda
Marcello DeMiranda on 27 Apr 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
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 Comment
Sriram Tadavarty
Sriram Tadavarty on 27 Apr 2020
It rises because x and A are not compatible. To figure out what the compatible matrices are, have a look here.
Hope this helps.

Answers (1)

Sriram Tadavarty
Sriram Tadavarty on 27 Apr 2020
Edited: Sriram Tadavarty on 27 Apr 2020
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');

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!