Possible Duplicate:
How can I index a MATLAB array returned by a function without first assigning it to a local variable?
我想对函数的输出使用索引。我使用 textscan 函数读取非常大的文本文件(15 GB)。在我的例子中,textscan 函数的返回是一个 1x1 元胞数组,其中包含一个非常大的数值数组。
而不是这样做:
tmp = textscan(...);
final_result = mat2cell(tmp{1,1});
我想做:
final_result = mat2cell( textscan(...){1,1} );
如果这可行,它将避免创建非常大的临时变量 tmp。还有其他方法可以避免临时变量吗?
最佳答案
如果您仍然想知道,请考虑以下示例:
%# some function that returns a cell array (TEXTSCAN in your case)
myFunc = @() {rand(5,5)};
%# normally you would write
C = myFunc();
C = C{1,1};
这是 @gnovice 的 cellarray 版本回答链接的问题(丑陋但有效):
%# equivalent to: C = myFunc(){1,1}
C = subsref(myFunc(), struct('type','{}','subs',{{[1 1]}}))
关于matlab - 如何对函数的输出使用索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6872875/