Removing specific value from cell array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mausmi Verma
il 26 Nov 2021
Commentato: Les Beckham
il 28 Nov 2021
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
0 Commenti
Risposta accettata
Les Beckham
il 26 Nov 2021
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
for i = 1:numel(A)
A{i}(A{i}==i) = [];
end
A
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!