|
Dear Kurt,
> for i = 1:aircraft
> iname = num2str(i);
> filename = strcat('C:\route_cost_ac',iname,'.mat');
> load(filename);
> %wall of other code
> end
>
> However, using this method the script becomes very slow, according to the profiler due to the strcat command (and in a lesser extent the num2str).
No. STRCAT and NUM2STR are not the problem. I did not ask my crystal ball, but the output of the profiler has a limited validity if the JIT-accelerator reorders the commands in a function.
LOAD without catching the output in a variable floods the workspace with variables. The dynamically added variables fill the internal lookup-table of pointers to names and data of variables. Therefore the FOR loop gets slower and slower. And even NUM2STR and STRCAT can get slower, but this is not caused by the functions, but by the polluted lookup-tables.
Please try to catch the loaded data in a struct:
S = load(filename);
Now the new variables are separated from the workspace.
Btw.: What happens, if the loaded data contain a variable called "strcat", e.g. a function handle... Can you guess it? Can you imagine, that Matlab needs intelligent (== slow) methods to catch this?
Kind regards, Jan
|