Delete rows from cell array in a for loop
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I want to delete one row in each iteration in a for loop. For example in iteration 1 I want to delete row 1, in iteration 2 I want to delete row 2 but I want to have row 1 in my cell array, in iteration 3 I want to delete row 3 but I want to have row 2 and 3 in my cell array. How can I do it?
2 commentaires
Jan
le 24 Oct 2022
Is this a typo: "delete row 3 but I want to have row 2 and 3"? Do you mean row 1 and 2?
Réponse acceptée
Jan
le 24 Oct 2022
Modifié(e) : Jan
le 24 Oct 2022
C = num2cell(magic(4));
n = height(C)
for k = 1:n
C2 = C;
C2(k, :) = [];
... your calculations come here
end
% Or:
m = true(n, 1);
for k = 1:n
m(k) = false;
C2 = C(m, :);
m(k) = true; % Reset for next iteration
... your calculations come here
end
0 commentaires
Plus de réponses (1)
David Hill
le 24 Oct 2022
for k=1:100
a=yourCell;%just copy yourCell to another variable
a(k,:)=[];%deletes row k
end
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!