Matrix dimensions error must agree

7 visualizaciones (últimos 30 días)
Ana Catalina
Ana Catalina el 11 de Oct. de 2018
Respondida: Rik el 11 de Oct. de 2018
I don't know why Im having problems doing this problems and I have change everything but still having matrix dimensions. here is my procedure. Thank you.
clc
clear
L=linspace(.4,1.3,3) %1x3
L1=linspace(1,1.5,3) %1x3
L2=linspace(.35,2.8,3) %1x3
L3=linspace(.87,2.4,3) %1x3
W2=linspace(100,300,4)%1x3
W3=linspace(150,400,4)%1x3
W4=linspace(120,300,4)%1x3
h1=linspace(1,2.2,3)%1x3
h2=linspace(.654,1.52,3)%1x3
theta=linspace(11,42,3)
alpha=linspace(42,76,3)
NE=linspace(10,24,3)
F1=linspace(450,1653,3)
[L,W2]=meshgrid(L,W2);
[L1,W3]=meshgrid(L1,W3);
[L2,W4]=meshgrid(L2,W4);
[F1,alpha]=meshgrid(F1,alpha);
[h1,h2]=meshgrid(h1,h2)
[NE,theta]=meshgrid(NE,theta)
figure(1)
W1=(2.*L.*F1.*cos(alpha)-(L-L2).*W2-L.*W3-(L-L3).*W4+(h1+h2).*sin(theta)+(L-(2.*L3)).*NE.*cos(theta)./L1);
  1 comentario
Rik
Rik el 11 de Oct. de 2018
Today I formatted your code, next time, use the {}Code button. See here for a GIF showing how to do it.

Iniciar sesión para comentar.

Respuestas (1)

Rik
Rik el 11 de Oct. de 2018
If you edit your calls to linspace where you ask for a 4-element vector, the code exits without error. Since your code is a bit light on comments I can't tell you if it now actually does what it should do.
As a note: in debugging settings, use clearvars instead of clear or clear all. Outside of debugging, don't use either, but use functions to keep your workspace clean.
clc
clearvars
L=linspace(.4,1.3,3) %1x3
L1=linspace(1,1.5,3) %1x3
L2=linspace(.35,2.8,3) %1x3
L3=linspace(.87,2.4,3) %1x3
W2=linspace(100,300,3)%1x3
W3=linspace(150,400,3)%1x3
W4=linspace(120,300,3)%1x3
h1=linspace(1,2.2,3)%1x3
h2=linspace(.654,1.52,3)%1x3
theta=linspace(11,42,3)
alpha=linspace(42,76,3)
NE=linspace(10,24,3)
F1=linspace(450,1653,3)
[L,W2]=meshgrid(L,W2);
[L1,W3]=meshgrid(L1,W3);
[L2,W4]=meshgrid(L2,W4);
[F1,alpha]=meshgrid(F1,alpha);
[h1,h2]=meshgrid(h1,h2)
[NE,theta]=meshgrid(NE,theta)
W1=(2.*L.*F1.*cos(alpha)-(L-L2).*W2-L.*W3-(L-L3).*W4+(h1+h2).*sin(theta)+(L-(2.*L3)).*NE.*cos(theta)./L1);

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by