reading a workspace value inside a function
이전 댓글 표시
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
Stephen23
2019년 7월 11일
"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
2019년 7월 11일
편집: Asliddin Komilov
2019년 7월 11일
"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
2019년 7월 12일
Asliddin Komilov
2019년 7월 12일
Walter Roberson
2019년 7월 12일
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
2019년 7월 13일
편집: Asliddin Komilov
2019년 7월 13일
Asliddin Komilov
2019년 7월 14일
편집: Asliddin Komilov
2019년 7월 14일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!