removing 0 values from an array while maintaining an array
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i have used data(data == 0) = [] to remove the 0's however it shifts the remaining numbers into columns rather than keeping the array layout? wondering if there is a way to keep it in array format and remove 0 values.
0 Commenti
Risposte (1)
Voss
il 30 Mar 2022
If you know there are always the same number of zeros in each column, you can reshape after removing them:
% random matrix with one zero in each column:
M = rand(7,3);
M([7 9 18]) = 0
n_zeros = 1; % one zero per column
M = reshape(M(M ~= 0),size(M)-[n_zeros 0])
0 Commenti
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices 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!