How can I index a MATLAB array returned by a function without first assigning it to a local variable?

前端 未结 9 1651
盖世英雄少女心
盖世英雄少女心 2020-11-21 05:02

For example, if I want to read the middle value from magic(5), I can do so like this:

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

to get

9条回答
  •  爱一瞬间的悲伤
    2020-11-21 06:01

    Your initial notation is the most concise way to do this:

    M = magic(5);  %create
    value = M(3,3);  % extract useful data
    clear M;  %free memory
    

    If you are doing this in a loop you can just reassign M every time and ignore the clear statement as well.

提交回复
热议问题