开发者

Loop assignment doubt

What does result mean inside a while loop in Matlab

while (some_condition == 1)

   A = somefunc();
   result(iterati开发者_如何学编程on) = A;
   iteration = iteration + 1; 
   ...

end


The only reasonable option seems to be that result is a variable (array or matrix) defined outside of your while loop and you assign the value A to index iteration of result.

[Edit] The second option is: result is function taking as argument iteration. While this is in theory possible, it makes no sense, since assigning a value to the result of a function in MATLAB will create a variable with that function's name and as a result hide that function in the scope of the variable.

E.g. try:

a = randi(10, 10, 2);
sum(a) = 5
b = 6;
sum(b)

As you will see, sum(b) does not return 6 (= b). It now returns the 6th element of the array sum, which was set to 5 in the 2nd line of code. Access to the function just became impossible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜