MATLAB: Don’t these matrix dimensions agree

matrix dimension

Nlayers=20; %number of layers in the lung
z=(1:Nlayers);
TLC=7; %total lung capacity
Htot=0.16; %total lung height, metres
plung=300; %lung density kg/m3
Vad=0.15; %Volume of the anatomical dead space
g=9.81; %Gravitational acceleration
Fs=64;
dt=1/Fs;
StopTime=8;
t=(0:dt:StopTime-dt);
Nalvtot=300;
Nalvz=Nalvtot/Nlayers; %Number of alveoli in a layer
r=(0.00009)*sin(1.57*t)+(0.00013); %alveolar radius
Valvz=(4/3)*pi*r.^3; %volume of the alveolus
Vtotal=Vad+Nalvz*Valvz*20;
Pcw=0.71-((0.95*TLC)/((Vtotal/TLC)-(0.22*TLC))-1)*0.58; %Pressure component of the chest wall

When i run this it says
"Error using /
Matrix dimensions must agree.
Error in Pcw_stripped (line 21)
Pcw=0.71-((0.95*TLC)/((Vtotal/TLC)-(0.22*TLC))-1)*0.58; %Pressure component of the chest wall
Error in run (line 63)
evalin('caller', [script ';']);"
But I'm sure why? Help!

Best Answer

  • You need to vectorise that line, doing element-wise operations. In this instance, that means replacing (/) with (./).
    See if this improves your code:
    Pcw=0.71-((0.95*TLC)./((Vtotal./TLC)-(0.22*TLC))-1)*0.58; %Pressure component of the chest wall