error of vector must be same length

3 Ansichten (letzte 30 Tage)
gnanaguru murugan
gnanaguru murugan am 19 Jun. 2021
Kommentiert: Image Analyst am 20 Jun. 2021
function voltot2 = recruitment(PIP,PEEP,opmin,opmax)
A = 0.0072;
B = 0.0072;
K = 0.15;
voltot2=[];
open=[];
voltot=0;
lung_level_units=9000;
for i=1:length(PIP)
for pressure=PEEP:PIP
for SP = -0.5:0.5:14.5
for TOP = opmin:opmax
if opmin == 0 || opmin == opmax
TOP = opmax;
end
if pressure > (SP+TOP)
volm = A-B*exp(-K*(PIP-SP));
vol = volm*lung_level_units/(1+opmax-opmin);
else
vol = 0;
end
voltot = voltot+vol;
end
end
voltot2(end+1)=voltot;
end
end
phy_ode:
function dy = phy_ode_1(~,y,sp)
const=0.5;
top=0;
p_crit=sp+top;
dy=const*(y-p_crit);
end
call fn:
sp=-0.5:0.5:14.5;
PIP=35;
PEEP=0;
opmin=0;
opmax=0;
for i = 1:length(sp)
[t,y(:,i)]=ode45(@(t,y) phy_ode_1(t,y,sp(i)),0:0.5:10,35);
p=y(:,i);
vol=recruitment(PIP,PEEP,opmin,opmax);
plot(p,vol')
end
error:
I got error of vector must be same length. could you help me?
  3 Kommentare
gnanaguru murugan
gnanaguru murugan am 20 Jun. 2021
here I attach the code in .mat file
Image Analyst
Image Analyst am 20 Jun. 2021
@gnanaguru murugan, so did you post that just for completeness, because it's now working thanks to Walter's (as of yet unaccepted) Answer below? Or do you still have a problem even after trying his suggestions below?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Jun. 2021
PIP, PEEP, opmin ,opmax are all constants, so recruitment() invoked on those is always going to return the same thing.
p = y(:,i) on the other hand, is going to have one row for each time returned. You passed in a tspan that had more than 2 entries, so provided that the ode does not end early it should be the same length as the timespan, which is 21 entries. Let's test:
PIP=35;
PEEP=0;
opmin=0;
opmax=0;
vol=recruitment(PIP,PEEP,opmin,opmax);
size(vol)
ans = 1×2
1 36
Nope, it returns 36 entries, which does not match the 21 you get from ode45() with that tspan.
... What is the point of calculating recruitment inside the loop when the inputs are not going to change?
function voltot2 = recruitment(PIP,PEEP,opmin,opmax)
A = 0.0072;
B = 0.0072;
K = 0.15;
voltot2=[];
open=[];
voltot=0;
lung_level_units=9000;
for i=1:length(PIP)
for pressure=PEEP:PIP
for SP = -0.5:0.5:14.5
for TOP = opmin:opmax
if opmin == 0 || opmin == opmax
TOP = opmax;
end
if pressure > (SP+TOP)
volm = A-B*exp(-K*(PIP-SP));
vol = volm*lung_level_units/(1+opmax-opmin);
else
vol = 0;
end
voltot = voltot+vol;
end
end
voltot2(end+1)=voltot;
end
end
end

Weitere Antworten (0)

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by