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

1 view (last 30 days)
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

Accepted Answer

dpb
dpb on 20 Nov 2019
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!