How to add a third condition without making the function 3D

4 次查看(过去 30 天)
I have three indices I want to iterate through and each have their own conditions and functions. However, my end result will be a 2D plot. I simply want to check against an index and force the function to 0. I'm not sure what the best way to do this is.
I originally generate a 2x3 matrix of means for my lognormal distribution and want to plot them, which is determined by the two indices iDG_door and iDMdoor. There is a third index that I want to iterate through (iPre_fg) and I basically want to check when iPre_fg is 1, I force the CDF to 0 if x is below n_fg. I attempt to do this in the code below all the %%%%%%%%
% Define degradation states from Ma et al. "Research to develop flood
% barrier testing strategies for NPPs"
% Creating a cell array called DegState DegState = {'Success', 'Degradation', 'Failure'}
Dg_doorS1=1; DegState_door{Dg_doorS1}='Closed-Perfect';
Dg_doorS2=2; DegState_door{Dg_doorS2}='Closed-Degraded';
Dg_doorS3=3; DegState_door{Dg_doorS3}='Failure';
% Define HCLPF capacity reduction factors due to degraded seals (different capacity for each degradation level)
DegCapRed_door=[0.99; 0.75; 1E-17]; %Closed-Perfect, Closed-Degraded, Failure
% Define floodgate states
PreState_fg1=1; PreState_fg{PreState_fg1}='No Damage';
PreState_fg2=2; PreState_fg{PreState_fg2}='Failure';
fg_state =[1 1]; % Fg presence has no existence on median cap
% Define damage states
Dm_doorS0=1; DamState_door{Dm_doorS0}='Ds_0 = No Damage';
Dm_doorS1=2; DamState_door{Dm_doorS1}='Ds_1 = Failure';
% Define baseline capacity values for each damage state for non-degraded seal
BaselineMed_door(Dm_doorS0)= NaN; % capacity against no damage or more damage
BaselineMed_door(Dm_doorS1)=3.28084; %ft capacity failure, from test 9S Wells et al. "Non-watertight door performance experiments and analysis under flooding scenarios"
CL_door = []; L_door = [":","-"]; C_door=["g","b","r"]; %C indicates damage state, L indicates Degradation
zeta_door = 0.5;
% Calculate all fragility parameters for Lognormal Distribution
for iDG_door=1:length(DegState_door)
for iDMdoor=1:length(DamState_door)
if iDMdoor==Dm_doorS0%|| iDG==DgS3 %if damage state is in the DmS1, the lamda is almost 0 (cannot be zero bc lognormal)
lam_door(iDMdoor,iDG_door)=1e-17; %artificial -> probability will be 1.0 later
else
lam_door(iDMdoor,iDG_door)=BaselineMed_door(iDMdoor)*DegCapRed_door(iDG_door);
end
pd_frag_door{iDG_door}{iDMdoor}=makedist('Lognormal',log(lam_door(iDMdoor,iDG_door)),zeta_door); % Creating a 1xlength(DegState) cell, within each cell is another 1xlength(DamState)
CL_door{iDG_door}{iDMdoor}=L(iDG_door)+C(iDMdoor);
end
end
Incorrect number or types of inputs or outputs for function 'L'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for iDG_door=1:2%length(DegState) not doing whole length bc these are lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
for iDMdoor=2:length(DamState_door) % Not doing whole length bc these lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
x=[]; x=linspace(0,20,10000);
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
for iPre_fg=1 % When pre state IS installed or in state 1...
if x<=n_fg
Fx_door = 0;
else
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
end
end
plot(x,Fx_door,CL_door{iDG_door}{iDMdoor},'LineWidth',3); hold on %Plot fragility functions and line types
legct=legct+1; leg{legct}=strcat(DegState_door{iDG_door},'; ',DamState_door{iDMdoor}); %Legend
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2023-9-9
移动:Walter Roberson 2023-9-9
% Define degradation states from Ma et al. "Research to develop flood
% barrier testing strategies for NPPs"
% Creating a cell array called DegState DegState = {'Success', 'Degradation', 'Failure'}
Dg_doorS1=1; DegState_door{Dg_doorS1}='Closed-Perfect';
Dg_doorS2=2; DegState_door{Dg_doorS2}='Closed-Degraded';
Dg_doorS3=3; DegState_door{Dg_doorS3}='Failure';
% Define HCLPF capacity reduction factors due to degraded seals (different capacity for each degradation level)
DegCapRed_door=[0.99; 0.75; 1E-17]; %Closed-Perfect, Closed-Degraded, Failure
% Define floodgate states
PreState_fg1=1; PreState_fg{PreState_fg1}='No Damage';
PreState_fg2=2; PreState_fg{PreState_fg2}='Failure';
fg_state =[1 1]; % Fg presence has no existence on median cap
% Define damage states
Dm_doorS0=1; DamState_door{Dm_doorS0}='Ds_0 = No Damage';
Dm_doorS1=2; DamState_door{Dm_doorS1}='Ds_1 = Failure';
% Define baseline capacity values for each damage state for non-degraded seal
BaselineMed_door(Dm_doorS0)= NaN; % capacity against no damage or more damage
BaselineMed_door(Dm_doorS1)=3.28084; %ft capacity failure, from test 9S Wells et al. "Non-watertight door performance experiments and analysis under flooding scenarios"
CL_door = []; L_door = [":","-",".-"]; C_door=["g","b","r"]; %C indicates damage state, L indicates Degradation
zeta_door = 0.5;
% Calculate all fragility parameters for Lognormal Distribution
for iDG_door=1:length(DegState_door)
for iDMdoor=1:length(DamState_door)
if iDMdoor==Dm_doorS0%|| iDG==DgS3 %if damage state is in the DmS1, the lamda is almost 0 (cannot be zero bc lognormal)
lam_door(iDMdoor,iDG_door)=1e-17; %artificial -> probability will be 1.0 later
else
lam_door(iDMdoor,iDG_door)=BaselineMed_door(iDMdoor)*DegCapRed_door(iDG_door);
end
pd_frag_door{iDG_door}{iDMdoor}=makedist('Lognormal',log(lam_door(iDMdoor,iDG_door)),zeta_door); % Creating a 1xlength(DegState) cell, within each cell is another 1xlength(DamState)
CL_door{iDG_door}{iDMdoor}=L_door(iDG_door)+C_door(iDMdoor);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for iDG_door=1:2%length(DegState) not doing whole length bc these are lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
for iDMdoor=2:length(DamState_door) % Not doing whole length bc these lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
x=[]; x=linspace(0,20,10000);
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
for iPre_fg=1 % When pre state IS installed or in state 1...
if x<=n_fg
Fx_door = 0;
else
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
end
end
plot(x,Fx_door,CL_door{iDG_door}{iDMdoor},'LineWidth',3); hold on %Plot fragility functions and line types
legct=legct+1; leg{legct}=strcat(DegState_door{iDG_door},'; ',DamState_door{iDMdoor}); %Legend
end
end
Unrecognized function or variable 'n_fg'.
  4 个评论
Walter Roberson
Walter Roberson 2023-9-11
n_fg = 3;
legct = 0;
% Define degradation states from Ma et al. "Research to develop flood
% barrier testing strategies for NPPs"
% Creating a cell array called DegState DegState = {'Success', 'Degradation', 'Failure'}
Dg_doorS1=1; DegState_door{Dg_doorS1}='Closed-Perfect';
Dg_doorS2=2; DegState_door{Dg_doorS2}='Closed-Degraded';
Dg_doorS3=3; DegState_door{Dg_doorS3}='Failure';
% Define HCLPF capacity reduction factors due to degraded seals (different capacity for each degradation level)
DegCapRed_door=[0.99; 0.75; 1E-17]; %Closed-Perfect, Closed-Degraded, Failure
% Define floodgate states
PreState_fg1=1; PreState_fg{PreState_fg1}='No Damage';
PreState_fg2=2; PreState_fg{PreState_fg2}='Failure';
fg_state =[1 1]; % Fg presence has no existence on median cap
% Define damage states
Dm_doorS0=1; DamState_door{Dm_doorS0}='Ds_0 = No Damage';
Dm_doorS1=2; DamState_door{Dm_doorS1}='Ds_1 = Failure';
% Define baseline capacity values for each damage state for non-degraded seal
BaselineMed_door(Dm_doorS0)= NaN; % capacity against no damage or more damage
BaselineMed_door(Dm_doorS1)=3.28084; %ft capacity failure, from test 9S Wells et al. "Non-watertight door performance experiments and analysis under flooding scenarios"
CL_door = []; L_door = [":","-",".-"]; C_door=["g","b","r"]; %C indicates damage state, L indicates Degradation
zeta_door = 0.5;
% Calculate all fragility parameters for Lognormal Distribution
for iDG_door=1:length(DegState_door)
for iDMdoor=1:length(DamState_door)
if iDMdoor==Dm_doorS0%|| iDG==DgS3 %if damage state is in the DmS1, the lamda is almost 0 (cannot be zero bc lognormal)
lam_door(iDMdoor,iDG_door)=1e-17; %artificial -> probability will be 1.0 later
else
lam_door(iDMdoor,iDG_door)=BaselineMed_door(iDMdoor)*DegCapRed_door(iDG_door);
end
pd_frag_door{iDG_door}{iDMdoor}=makedist('Lognormal',log(lam_door(iDMdoor,iDG_door)),zeta_door); % Creating a 1xlength(DegState) cell, within each cell is another 1xlength(DamState)
CL_door{iDG_door}{iDMdoor}=L_door(iDG_door)+C_door(iDMdoor);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for iDG_door=1:2%length(DegState) not doing whole length bc these are lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
for iDMdoor=2:length(DamState_door) % Not doing whole length bc these lambdas are 0, so it's just a straight line at 1.0 starting at n_ins
x=[]; x=linspace(0,20,10000);
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
for iPre_fg=1 % When pre state IS installed or in state 1...
if x<=n_fg
Fx_door = 0;
else
Fx_door=[]; Fx_door=cdf(pd_frag_door{iDG_door}{iDMdoor},x); %Plot cdfs for fragility
end
end
plot(x,Fx_door,CL_door{iDG_door}{iDMdoor},'LineWidth',3); hold on %Plot fragility functions and line types
legct=legct+1; leg{legct}=strcat(DegState_door{iDG_door},'; ',DamState_door{iDMdoor}); %Legend
end
end
Joy Shen
Joy Shen 2023-9-11
Hi, I still have the issue that the functions need to be suppressed at 3 and below. I'm not sure how to accomplish this without using a 3D index.

请先登录,再进行评论。

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by