Repeating a task for each row without loop
Ältere Kommentare anzeigen
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 Kommentare
Bob Thompson
am 27 Mär. 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
am 27 Mär. 2018
Bob Thompson
am 27 Mär. 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
am 27 Mär. 2018
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!