如何索引由函数返回的 MATLAB 数组而不先将其分配给局部变量?

2021年11月20日 阅读数:3
这篇文章主要向大家介绍如何索引由函数返回的 MATLAB 数组而不先将其分配给局部变量?,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

问题:

For example, if I want to read the middle value from magic(5) , I can do so like this:例如,若是我想从magic(5)读取中间值,我能够这样作:数组

M = magic(5);
value = M(3,3);

to get value == 13 .得到value == 13 I'd like to be able to do something like one of these:我但愿可以执行如下操做之一:this

value = magic(5)(3,3);
value = (magic(5))(3,3);

to dispense with the intermediate variable.省去中间变量。 However, MATLAB complains about Unbalanced or unexpected parenthesis or bracket on the first parenthesis before the 3 .可是,MATLAB 会在3以前的第一个括号上抱怨Unbalanced or unexpected parenthesis or bracket括号。url

Is it possible to read values from an array/matrix without first assigning it to a variable?是否能够在不首先将其分配给变量的状况下从数组/矩阵中读取值?spa


解决方案:

参考: https://stackoom.com/en/question/FDZj