Repeating a task for each row without loop
Afficher commentaires plus anciens
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 commentaires
Bob Thompson
le 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
le 27 Mar 2018
Bob Thompson
le 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
le 27 Mar 2018
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!