Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Error: Matrix dimensions must agree

1 vue (au cours des 30 derniers jours)
Marcello DeMiranda
Marcello DeMiranda le 27 Avr 2020
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaire
Sriram Tadavarty
Sriram Tadavarty le 27 Avr 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.

Réponses (1)

Sriram Tadavarty
Sriram Tadavarty le 27 Avr 2020
Modifié(e) : Sriram Tadavarty le 27 Avr 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');

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by