When I load a struct, why does it change a variable in the workspace?

2 views (last 30 days)
Hi,
I am trying to run repeatedly a code that was given to me, using a while loop. Every time the loop runs, this code (femjr) clears all variables, then generates new variables. I have been 1.) loading a structure "fdat", 2.)populating fdat with output data, and 3.)saving fdat during each run of the loop. However, I realized that when I load fdat, at least some of the output variables from femjr get over-written. Why does this happen?
All fields in fdat were initialized at the beginning of my code.
Loop:
if true
% while fdat.iii<=fdat.sz
iname=fdat.iname{iii};
save('iname')
femjr
load('fdat')
iii=fdat.iii;
fdat.u{iii}=solution_vector;
fdat.x{iii}=0:1/(dof_num-1):1
fdat.E(iii)=energy;
iii=iii+1;
fdat.iii=iii;
save('fdat')
end
end
  1 Comment
Walter Roberson
Walter Roberson on 16 Mar 2014
Is femjr a function or a script? Does it use assignin()?
Why do you expect that variables in fdat will not overwrite values in the workspace? That is what load() is defined to do when you use it in that form.

Sign in to comment.

Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!