Add different numbers to numbers in vector and have multiple output vectors

2 views (last 30 days)
I have a vector of 1 row and 7 colomns, the first number is 0.
I want to add 1,-1,i,-i to a the first number in my vector as my second number, and add 1,-1,i,-i to the second number as my third number, etc until I get to number 7 and get all the vectors.
How can I achieve that?
  2 Comments
James Tursa
James Tursa on 25 Apr 2019
This is not clear. Can you give an example of what the first, second, and third numbers would be after the operations?
Haosheng Yang
Haosheng Yang on 25 Apr 2019
so the first number is 0, the second number would be 1, -1, i, -i; In the case of second number being 1, then the third number would be 2, 0, 1+i, 1-i.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 25 Apr 2019
bsxfun(@plus, [1,-1,i,-i].', YourRowVector)
Or if you have R2016b or later,
[1,-1,i,-i].' + YourRowVector
These will give a 4 x 7 array that you can then index to extract the parts you want.
  7 Comments
Walter Roberson
Walter Roberson on 30 Apr 2019
Use for loops. It isn't worth the effort to develop a vectorized solution (especially as I still do not understand what you want.)

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!