Matrix dimensions error must agree

7 Ansichten (letzte 30 Tage)
Ana Catalina
Ana Catalina am 11 Okt. 2018
Beantwortet: Rik am 11 Okt. 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 Kommentar
Rik
Rik am 11 Okt. 2018
Today I formatted your code, next time, use the {}Code button. See here for a GIF showing how to do it.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 11 Okt. 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);

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by