Function which relies on workspace and memory

51 Views Asked by At

I have a function which gets its inputs from a .mat file. This works just fine, but recently I had to update those variables and they increased by orders of magnitude in number. Therefore, the loading time increased.

Since the function is iterated 10 000 times this is a major problem now. You may ask, why do you load those workspace variables in the first place? The answer to this is that I import variables that may change from time to time which I save conveniently as workspace before calling the function. The previous code had those variables written in the script similar to a=1 b=4 etc., which only works if the user accesses the code which I rather avoid.

So the question is, how can I access those variables elegantly in a function?

function 
    load vars.mat
    execute statements ...
end

or

function 
    global vars
    execute statements
end

seem to be a much, much slower variant of

function
    a=1
    b=4 
    ...
    execute statements
end
0

There are 0 best solutions below