saving and writing variables in files

1 view (last 30 days)
nisha bhatt
nisha bhatt on 12 Oct 2020
Commented: Stephen23 on 12 Oct 2020
Hi
I am using a main function ..In that function, in a loop I am calling another function...In that another function there are 4 varaibles that need to be updated and i want to load values of these variables in every iteration ...how to do that...please note I am using ode15i...in which for rxample if the loop runs from t=0 to t=20 with step size of 1...Now say, The values of those 4 variables keeps on updating multiple times at t=0 instant till the consistent results have been achieved...and i want to store values of those values
currently I am doing this..........
fuction main()
for i=1:1:400
to=tdash(i);
[yo_new,ypo_new] = decic(@(t,y,yp)tryingode(t,y,yp),to,yo,[fixed_yo],ypo,[]);
[sol] = ode15i(@(t,y,yp)tryingode(t,y,yp),[0 20],yo_new,ypo_new);
[y,yp]=deval(sol,tdash(i));
si=y(2); % stress
T=y(1);
zo=y(3);
zso=y(4);
%
[yo]=[T si zo zso];
[ypo]=[yp];
end
function dydt=tryingode(t,y,yp)
persistent sij Tj zj zsj % I dont want to use persistent
if isempty(sij) % For the first time
sij=80;
Tj=26;
zsj=0.71 ;
zj=1;
end
if (y(2)+Ca*(Af-y(1)))>=0 && (y(2)+Ca*(As-y(1)))<=0 && alpha>=-(pi-phia)&& alpha<=phia % Ca Af As phia =constant .....alpha =atan(yp(2),yp(1))
else
sij=y(2); % Want to store these values in files and then call these values in next iteration
Tj=y(1);
zj=y(3);
zsj=y(4);
end
Any method to avoid persistent .......Here at start , my assumed values lead me to else condition of function and I get updated value of sij Tj zj zsj but when if condition follows the persistent values makes values vary differently.......is there any other method .....What I am thinking is ...if there is any means where i can save these sij Tj zj zsj values (may be in a file ) and instead of making them persistent variables, I call the previous value in function from file.......(first write to file sij etc values in local function and then read those save values in files when local function is called in next iteration)?
I hope my question is clear ...

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by