Repeating a task for each row without loop
Show older comments
I'd like to do this expression without a loop,
x = [1, 1; 2, 2; 3, 3; 4, 7; 8, 8; 9, 9; 10, 15; 16, 16; 17, 17];
for i = 1:size(x,1)
y(i,1) = {[x(i,1):x(i,2)]}
end
Thanks in advance,
4 Comments
Bob Thompson
on 27 Mar 2018
So, you just want to set each row of y to be a cell containing the corresponding row of x? How are you using y later in your code? Do you need to even specify y as a separate variable, or can you just index x later on?
Jonathan Pelletier-Marcotte
on 27 Mar 2018
Bob Thompson
on 27 Mar 2018
Ok. I personally don't know of a way to conduct a specific operation for each row of a matrix without defining a loop to run through the rows. It might be possible with some fancy indexing, but I don't know how.
Jonathan Pelletier-Marcotte
on 27 Mar 2018
Accepted Answer
More Answers (0)
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!