passing a mat file variable to a function
이전 댓글 표시
I have written a function myfun.m which works on a very large input variable var stored in a file myfile.mat in the current folder. If I first load var into the workspace and then call myfun(var), var requires memory of twice its size because it is kept both in the base and the function workspace. How can I instead pass just the names of myfile.mat and var on calling myfun, and load var from within myfun? Thank you!
채택된 답변
추가 답변 (1개)
댓글 수: 1
Stephen23
2018년 7월 20일
A much better solution would be to load into an output variable and then simply access its field:
S = load(filename,varname);
var = S.(varname);
카테고리
도움말 센터 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!