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!