Only the last value are being stored in for loop
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I just need to have a and c store array of numbers rather than store the last number. I need to sample from [a,c] and a should be something like [0 0.5 1 1.5...] and c should be [0.5 1 1.5 2...] but as of right now a and c just take the last values, 5 and 20.
Nsim = 10000;
IBinEdges=[0:0.5:5 20]; %ft
IBinEdges_Lo=IBinEdges(1:end-1);
IBinEdges_Hi=IBinEdges(2:end);
IBinEdges_Md=IBinEdges_Lo+(diff(IBinEdges)/2);
%This is external flood (nominal) elevation
ExtSurgeBinEdges = [0:0.5:5 20];
ExtSurgeBinEdges_Lo=ExtSurgeBinEdges(1:end-1);
ExtSurgeBinEdges_Hi=ExtSurgeBinEdges(2:end);
ExtSurgeBinEdges_Md=ExtSurgeBinEdges_Lo+(diff(ExtSurgeBinEdges)/2);
% Generation every combination of external flood height and seal state
% iterations
IndF=[1:length(ExtSurgeBinEdges_Md)]';
IndA=[1:length(DamState)]';
temp1=[]; temp2=[]; [temp1,temp2]=ndgrid(IndF,IndA);
IndMatFA=[temp1(:),temp2(:)];
% col1: surge height
% col2: seal condition
% This is where the issue is, a and c needs to contain each bin edge for
% ExtSurgeBinEdges low and high. it just has the extremes
% Use MC simulation to generate CPT for IF node
for iComb=1:size(IndMatFA,1) % loop over combinations of damage state and external flood height
% Define distribution of external flood height within bin and sim:
a=[]; a=ExtSurgeBinEdges_Lo(IndMatFA(iComb,1));
b=[]; b=ExtSurgeBinEdges_Md(IndMatFA(iComb,1));
c=[]; c=ExtSurgeBinEdges_Hi(IndMatFA(iComb,1));
pd1=[]; pd1=makedist('Uniform',a,c);
Fsim=[]; Fsim=random(pd1,[Nsim,1]); %simulate external flood heights within bin (Uniform)
Fsim=Fsim.*(Fsim>=0); % make sure the difference is never below zero
end
1 个评论
VBBV
2023-4-10
编辑:VBBV
2023-4-10
Isnt this supposed to be outside of loop ?
% iComb=1:size(IndMatFA,1);
a=[];
b=[];
c=[];
pd1=[];
Fsim=[];
Can you tell which difference is never below zero ? Do you mean successive Fsim values generated using uniform distribution ?
% which Difference is never below zero ? this line is confusing
Fsim=Fsim.*(Fsim>=0); % make sure the difference is never below zero
采纳的回答
VBBV
2023-4-6
编辑:VBBV
2023-4-6
a(iComb)=ExtSurgeBinEdges_Lo(IndMatFA(iComb,1));
b=[]; % put this line outside of loop
b(iComb)=ExtSurgeBinEdges_Md(IndMatFA(iComb,1));
c=[]; % this too
c(iComb)=ExtSurgeBinEdges_Hi(IndMatFA(iComb,1));
3 个评论
VBBV
2023-4-10
编辑:VBBV
2023-4-10
Nsim = 10000;
IBinEdges=[0:0.5:5 20]; %ft
IBinEdges_Lo=IBinEdges(1:end-1);
IBinEdges_Hi=IBinEdges(2:end);
IBinEdges_Md=IBinEdges_Lo+(diff(IBinEdges)/2);
%This is external flood (nominal) elevation
ExtSurgeBinEdges = [0:0.5:5 20];
ExtSurgeBinEdges_Lo=ExtSurgeBinEdges(1:end-1);
ExtSurgeBinEdges_Hi=ExtSurgeBinEdges(2:end);
ExtSurgeBinEdges_Md=ExtSurgeBinEdges_Lo+(diff(ExtSurgeBinEdges)/2);
% Generation every combination of external flood height and seal state
% iterations
IndF=[1:length(ExtSurgeBinEdges_Md)]';
IndA=[1:length(DamState)]';
temp1=[]; temp2=[]; [temp1,temp2]=ndgrid(IndF,IndA);
IndMatFA=[temp1(:),temp2(:)];
% col1: surge height
% col2: seal condition
% This is where the issue is, a and c needs to contain each bin edge for
% ExtSurgeBinEdges low and high. it just has the extremes
% Use MC simulation to generate CPT for IF node
% isnt this supposed to be as in a loop ??
% iComb=1:size(IndMatFA,1);
a=[];
b=[];
c=[];
pd1=[];
Fsim=[];
for iComb=1:size(IndMatFA,1)
% loop over combinations of damage state and external flood height
% Define distribution of external flood height within bin and sim:
a(iComb)=ExtSurgeBinEdges_Lo(IndMatFA(iComb,1));
b(iComb)=ExtSurgeBinEdges_Md(IndMatFA(iComb,1));
c(iComb)=ExtSurgeBinEdges_Hi(IndMatFA(iComb,1));
pd1=makedist('Uniform','Lower',a(iComb),'Upper',c(iComb)); %***
Fsim(:,iComb)=random(pd1,[Nsim,1]); %simulate external flood heights within each bin (Uniform)
end
% check if the difference is never below zero
Fsim=Fsim.*(Fsim>=0); % make sure the difference is never below zero
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Help and Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!