How to iterate an if statement condition and store values in separate columns
3 次查看(过去 30 天)
显示 更早的评论
I'm trying to calculate Esim for different boundary conditions on Fsim. The first being if Fsim is less than n_ins, the second if Fsim is between n_ins and n_tot, and the third if Fsim is above n_tot.
However, I want to have three different values of n_tot. Is there a way to calculate this piecewise function, where one of the boundary conditions has three different values? I essentially would like Esim to have three columns of data for each n_tot(i).
This is what I have so far:
Qsim=[]; Qsim=Cd.*Asim.*sqrt(2*g*(Fsim-n_ins))*Dsim;
Vsim=[]; Vsim=Qsim.*Dsim; %ft^3
n_tot=[12 13 14];
for i=1:1:3
if (Fsim < n_ins)
Esim = 0;
elseif (Fsim >= n_ins & Fsim < n_tot(i))
Esim(:,i)=Vsim./(int_L*int_W);
elseif (Fsim>= n_tot(i))
Esim = int_L*int_W*int_H; % make sure this is here
end
end
0 个评论
回答(1 个)
DUY Nguyen
2023-3-2
Hi,
You can try something like this! Esim will have three columns of data for each n_tot(i)
Qsim = Cd.*Asim.*sqrt(2*g*(Fsim-n_ins))*Dsim;
Vsim = Qsim.*Dsim; %ft^3
n_tot = [12 13 14];
Esim = zeros(length(Vsim), length(n_tot));
for i = 1:length(n_tot)
if (Fsim < n_ins)
Esim(:,i) = 0;
elseif (Fsim >= n_ins && Fsim(j) < n_tot(i))
Esim(:,i) = Vsim(j)/(int_L*int_W);
elseif (Fsim >= n_tot(i))
Esim(:,i) = int_L*int_W*int_H;
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!