error of vector must be same length

2 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2021-6-20
@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?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2021-6-19
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Historical Contests 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by