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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!