Removing specific value from cell array

Lets suppose i have a cell array as:
A={[1 2 4 6 7]; [1 2 5 7 9 8]; [3 4 6 8]; [1 2 3 4 5 6]]
now i want to remove the element from each cell based on the cell index and want answer like
A={[2 4 6 7]; [1 5 7 9 8]; [4 6 8]; [1 2 3 5 6]}
thanks in advance

 採用された回答

Les Beckham
Les Beckham 2021 年 11 月 26 日

0 投票

There may be a more compact (i.e., single line) way to do this but this works and is not too complex:
A={[1 2 4 6 7]; [1 2 5 7 9 8]; [3 4 6 8]; [1 2 3 4 5 6]}; % note that I replaced your ] at the end with }
A
A = 4×1 cell array
{[ 1 2 4 6 7]} {[1 2 5 7 9 8]} {[ 3 4 6 8]} {[1 2 3 4 5 6]}
for i = 1:numel(A)
A{i}(A{i}==i) = [];
end
A
A = 4×1 cell array
{[ 2 4 6 7]} {[1 5 7 9 8]} {[ 4 6 8]} {[1 2 3 5 6]}

3 件のコメント

Mausmi Verma
Mausmi Verma 2021 年 11 月 27 日
Thank you for ur answer
Les Beckham
Les Beckham 2021 年 11 月 27 日
You are welcome.
Les Beckham
Les Beckham 2021 年 11 月 28 日
If this answered your question, please accept the answer. Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2021 年 11 月 26 日

コメント済み:

2021 年 11 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by