Add different numbers to numbers in vector and have multiple output vectors
2 views (last 30 days)
Show older comments
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
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?
Answers (1)
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
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.)
See Also
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!