While循环Matlab中的指令

时间:2011-03-31 04:48:05

标签: matlab

这条指令vector=[vector,sum(othervector)]在while循环中的matlab中做了什么,如:

vector=[]; 

while a - b ~= 0
  othervector = sum(something') %returns a vector
  vector=[vector,sum(othervector)]; %it keeps a new vector?
  ...

end

vector=vector./100

1 个答案:

答案 0 :(得分:3)

执行a = [a,b]表示将b附加到a,因此vector最终将成为一个矩阵,其中每列是something'的行方和。


更具体地说:假设something'是这个矩阵:

something' = [ 1, 2; 3, 4 ];

然后sum(something')是:

othervector = [ 3 ; 7 ]

最初vector为空,因此将vector设置为

vector = [ 3 ; 7 ]

假设我们重复使用由

组成的新something'
[ 5, 5; 5, 6 ]

然后sum(something')是:

othervector = [ 10; 11 ]

现在我们使用vector

将其增加到vector = [vector, sum(othervector)]
vector = [ vector, [10; 11] ] = [ 3, 10 ; 7, 11 ]