From: Heinz on
Hello

I have a problem within a Program that is having about the followin structure:


for i=1: NumberOfSystems
Setsystem(i);
% This function writes an m File script System.m that does contain the system
% information on the i-th system.
rehash
clear mex

DoCalculation('system.m')
% Within this function one of the first commands is evaluate('system.m')
end

The Problem within this costruction lies in the fact, that matlab caches functions, that once have been used. And it DOES NOT check on every use of the function, whether there is a newer version on the disk. The only way matlab realises, that there has been a change is to save it using the matlab editor. So if I start the program I will calculate the first system forever. Because the system.m on the disk is changed, but not the cached one.

I got the impression, that rehash should do the trick, but it didn't work. There was no effect at all.
I had the slight hope that clear mex could work. There was no effect at all.

With the help of matlab support I came to the conclusion, that the only way is to name the systems: system1.m system2.m ...

This did work, but is also very dangerous.
If i realise, that there was an error in the file that produces the input files, an I change this, and I restart the complete calculation. --> Then Im still performing the old calculations, because matlab has not realized, that this time there is a new set of systemi.m

Only way to do the calculation in this manner is now to end matlab, delete all system"i" files, and restart matlab.


Do you have any suggestions?

Does anybody know, how the Matlab editor tells Matlab, that the File xy has changed?



Only further idea I have is, that I could name the files: system"actualTimeDownToTheSecond".m But I don't really want to do this.
Gr HW
From: Steven_Lord on


"Heinz " <heinz.widmer(a)ch.schindler.com> wrote in message
news:i40m9t$54n$1(a)fred.mathworks.com...
> Hello
> I have a problem within a Program that is having about the followin
> structure:
>
> for i=1: NumberOfSystems
> Setsystem(i);
> % This function writes an m File script System.m that does contain the
> system % information on the i-th system.

Don't do this.

> rehash clear mex
>
> DoCalculation('system.m')
> % Within this function one of the first commands is
> evaluate('system.m')
> end
>
> The Problem within this costruction lies in the fact, that matlab caches
> functions, that once have been used. And it DOES NOT check on every use of
> the function, whether there is a newer version on the disk. The only way
> matlab realises, that there has been a change is to save it using the
> matlab editor. So if I start the program I will calculate the first
> system forever. Because the system.m on the disk is changed, but not the
> cached one.

Or if you clear the function from memory, but that will mean MATLAB will
need to reparse the file each and every time you run it, so it WILL have an
impact on the performance of your program.

Don't do this. If you must, save the information about the system to a
variable then LOAD that variable into your function instead of rewriting
functions on the fly.

> I got the impression, that rehash should do the trick, but it didn't work.
> There was no effect at all.
> I had the slight hope that clear mex could work. There was no effect at
> all.
>
> With the help of matlab support I came to the conclusion, that the only
> way is to name the systems: system1.m system2.m ...
>
> This did work, but is also very dangerous. If i realise, that there was an
> error in the file that produces the input files, an I change this, and I
> restart the complete calculation. --> Then Im still performing the old
> calculations, because matlab has not realized, that this time there is a
> new set of systemi.m
> Only way to do the calculation in this manner is now to end matlab, delete
> all system"i" files, and restart matlab.
>
>
> Do you have any suggestions?

Yes. DO NOT DO THIS.

> Does anybody know, how the Matlab editor tells Matlab, that the File xy
> has changed?
>
>
> Only further idea I have is, that I could name the files:
> system"actualTimeDownToTheSecond".m But I don't really want to do this.
> Gr HW

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

From: Heinz on
Is there really no way to trigger the "reparsing"?

The performance issue that you mentioned is of no issue to me. Because the calculation of a system takes several minutes, while the setting up of the system takes even under the worst cases less than 0.1 seconds.

somehow the editor is capable to trigger the reparsing, why can't I as a user not do this?


GR HW

PS: I would never to this in a the most inner loop of an ODE calculation. But there is no more economic way than to do it this way.
From: Steven_Lord on


"Heinz " <heinz.widmer(a)ch.schindler.com> wrote in message
news:i43g1p$ofu$1(a)fred.mathworks.com...
> Is there really no way to trigger the "reparsing"?

CLEAR the function from memory.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com