0

What does this instruction vector=[vector,sum(othervector)] does in matlab inside a while loop like:

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 Answer 1

3

Executing a = [a,b] means append b to a, thus vector will eventually be a matrix where each column is the row-wise sum of something'.


More concretely: suppose something' is this matrix:

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

Then sum(something') is:

othervector = [ 3 ; 7 ]

And initially vector is empty, so this sets vector to

vector = [ 3 ; 7 ]

Suppose we repeat with a new something' consisting of

[ 5, 5; 5, 6 ]

Then sum(something') is:

othervector = [ 10; 11 ]

And now we augment this to vector using vector = [vector, sum(othervector)]:

vector = [ vector, [10; 11] ] = [ 3, 10 ; 7, 11 ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.