Changing Global Variable

2 views (last 30 days)
Peiwen Lau
Peiwen Lau on 20 Feb 2012
I am simulating a fluidized bed system, in which I would like to pass two values calculated from ODE45 as input into other functions. Since the two calculated values of the ODE45 changes every time, I have to export the calculations into .mat file (and using -append to store the latest calculated values), and then read these values by using dlmread. But this is taking a long time, approx. 15 days.
Is there any methods for me to perform this task (i.e. share the two calculated values, without using global, and without using the passing argument)? Please help me as I am officially stuck for a week now.
Thank you.

Answers (2)

Image Analyst
Image Analyst on 20 Feb 2012
Wow, I've never heard of dlmread taking 15 days. How big are the files? In fact I've never heard of anyone even using dlmread to read .mat file - I always hear of people using load() to read .mat files. Anyway, I'm not sure why you can't just pass in your arguments via the argument list. So what if they change every time? Usually arguments change every time - that's why functions are built. But you can use setappdata() and getappdata() if you want to, though I still don't know why that would be necessary. Or you can read the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F

Peiwen Lau
Peiwen Lau on 20 Feb 2012
Thanks for your reply. I used load to read the .mat files. Sorry my bad for making the mistake. My simulation involves solving odes & using the -append function has slowed the calc. I used the functions to pass & accept initial guess & answers from ode, that's why I am unable to pass by argument here.
I am looking for a solution to pass calculated values from ode from the ode caller function into another function. The ode output values changes every seconds, so I need the function to be able to get updated values. The code below is what I would like to achieve - to share the updated ode_ans with the other function.
function odecaller [t,ode_ans]=ode45('odesets',[tstart:tspan:tfinal],ode_init); %ode45 pass_value=ode_ans(end); end %end function odecaller
function ode_solution=odeupdater(~,ode_ans) %pass back ode_ans accept_pass_value=pass_value; %from odecaller ode_solution= [ode equations here]; end %end function odeupdater
Please help me out with this. Thank you very much.

Community Treasure Hunt

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

Start Hunting!