Delete rows from cell array in a for loop

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 件のコメント

Jan
Jan 2022 年 10 月 24 日
Is this a typo: "delete row 3 but I want to have row 2 and 3"? Do you mean row 1 and 2?
Dexter
Dexter 2022 年 10 月 24 日
Yes

サインインしてコメントする。

 採用された回答

Jan
Jan 2022 年 10 月 24 日
編集済み: Jan 2022 年 10 月 24 日

0 投票

C = num2cell(magic(4));
C = 4×4 cell array
{[16]} {[ 2]} {[ 3]} {[13]} {[ 5]} {[11]} {[10]} {[ 8]} {[ 9]} {[ 7]} {[ 6]} {[12]} {[ 4]} {[14]} {[15]} {[ 1]}
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

その他の回答 (1 件)

David Hill
David Hill 2022 年 10 月 24 日

1 投票

for k=1:100
a=yourCell;%just copy yourCell to another variable
a(k,:)=[];%deletes row k
end

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2022 年 10 月 24 日

編集済み:

Jan
2022 年 10 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by