Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Error: Matrix dimensions must agree

1 visualización (últimos 30 días)
Marcello DeMiranda
Marcello DeMiranda el 27 de Abr. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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 comentario
Sriram Tadavarty
Sriram Tadavarty el 27 de Abr. de 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.

Respuestas (1)

Sriram Tadavarty
Sriram Tadavarty el 27 de Abr. de 2020
Editada: Sriram Tadavarty el 27 de Abr. de 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');

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by