reading a workspace value inside a function
Afficher commentaires plus anciens
I used xlsread in a function. now I have another function that uses this function, and that function is used by a script. So xlsread is used 100 of times uselessly and I am getting 'out of memory' error (this maybe is not the main cause of the error). if I take xlsread into the script, the function cannot read the read variable, even it is in the workspace. How do I make the function to use the variable, without making it input variable of the function?
thanks
10 commentaires
Stephen23
le 11 Juil 2019
"without making it input variable of the function?"
Why not?
Passing data as input/output arguments is the simplest and most efficient way of passing data between workspaces.
Asliddin Komilov
le 11 Juil 2019
Modifié(e) : Asliddin Komilov
le 11 Juil 2019
"I will have to do it for the all functions above on hierarchy..."
Possibly, but without seeing an architecture or the code we can only guess what you are doing.
"...I would rather try/learn some other way if its there"
There are always multiple ways of doing things: you could use nested functions.
Asliddin Komilov
le 12 Juil 2019
Asliddin Komilov
le 12 Juil 2019
Walter Roberson
le 12 Juil 2019
persistent xlsread_memoized
if isempty(xlsread_memoized)
xlsread_memoized = memoize(@xlsread) ;
end
C = xlsread_memoized(filename);
As long as the filename does not change, the previously read values will be pulled from memory instead of re-reading the file. This would be through the typical copy-on-write mechanism so additional memory would not be needed.
Asliddin Komilov
le 13 Juil 2019
Modifié(e) : Asliddin Komilov
le 13 Juil 2019
Asliddin Komilov
le 14 Juil 2019
Modifié(e) : Asliddin Komilov
le 14 Juil 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!