MATLAB Answers

0

How to use a code to get the corresponding value of a loop in another file

joshua Abam さんによって質問されました 2019 年 11 月 20 日 11:57
最新アクティビティ dpb
さんによって コメントされました 2019 年 11 月 23 日 0:24
dpb
さんの 回答が採用されました
I have a particular challenge in a project I am trying to round up. I have two files with loops on both files which I need to interact correspondingly that is to say both files contain the same loops. As such what I am looking is a case where the primary (main) file start with a value of 1 goes to the other file picks the value of one as well run the process have the value comes back thru the loop pick the next value of 2 goes all over again to the secondary file pick 2 comes back till the end of the loop.
The second challenges I am having is the identification of files generated by the second file as that is the information needed by the first file
% This is the first file
function D_fat = scr_response(x)
;;;;;;;;
;;;;;;;;
environment.WaveDirection = 0.0;
for environment_wavedirection = 0:45:360
if environment_wavedirection < 360
environment.WaveDirection = environment_wavedirection;
end
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
for scores = [caseload01(x),caseload02(x),caseload03(x)]
;;;;;
;;;;;
D_fat = xlsread('filename.xlsx',1,'B8')
D_total = sum(D_fat)
end
end
end
% This is the second file
function seastateload1 = case01(x)
;;;;;;;
;;;;;;;
;;;;;;;
for environment_wavedirection = 0:45:360
if environment_wavedirection < 360
environment.WaveDirection = environment_wavedirection;
end
model.CalculateStatics;
model.RunSimulation; %Run the Dynamic simulation
model.SaveSimulation(sprintf('loadcase1Hs%d.sim',environment.WaveDirection));
%I need the name of the file generated as that is what is needed in file 1
seastateload1 = 'generated file name'
end
end

  0 件のコメント

サインイン to comment.

1 件の回答

dpb
回答者: dpb
2019 年 11 月 20 日 14:32
 採用された回答

Your outer loop range is 0:45:360 but you only set a value for the struct environment for those values less than 360. What is it supposed to do at 360? As coded, it will rerun with the 315 value left over from the previous iteration. Looks like you should probably just quit? Or adjust the upper limit of loop to 360-45.
For the filename, just save the name you created as a variable instead of burying it inside the argument of the .SaveSimulation method--
function seastateload1 = case01(x)
...
...
seastateload1=sprintf('loadcase1Hs%d.sim',environment.WaveDirection);
model.SaveSimulation(sprintf(seastateload1 ,environment.WaveDirection));
end
end

  13 件のコメント

joshua Abam 2019 年 11 月 22 日 12:32
Dear Dpd
Thanks for all your help it was indeed appreciated.
Thanks
kind regards
Joshua Abam
joshua Abam 2019 年 11 月 22 日 20:12
Dear Dpd
I have one more challenge
I wish to know how to sum all the output generated from the for loop. in these instance the generate results from D_fat
Thanks
function D_fat = response(x)
;;;;;;;;
;;;;;;;;
;;;;;;
;;;;;;;;
dTheta = 45
MaxTheta = 360-dTheta
D_total = 0.0;
for strength = 0:dTheta:MaxTheta
WaveDirection = strength;
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
;;;;;
;;;;;
D_fat = xlsread('filename.xlsx',1,'B8')
%The idea is to sum all the generated D_fat from the for loop above
D_total = sum(D_fat)
dpb
2019 年 11 月 23 日 0:24
Just keep a running sum...

サインイン to comment.



Translated by