reading a workspace value inside a function
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 11 de Jul. de 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
el 11 de Jul. de 2019
Editada: Asliddin Komilov
el 11 de Jul. de 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
el 12 de Jul. de 2019
Asliddin Komilov
el 12 de Jul. de 2019
Walter Roberson
el 12 de Jul. de 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
el 13 de Jul. de 2019
Editada: Asliddin Komilov
el 13 de Jul. de 2019
Asliddin Komilov
el 14 de Jul. de 2019
Editada: Asliddin Komilov
el 14 de Jul. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!