How to remove zeros from an array without using nonzeros command
Mostra commenti meno recenti
i want to delete the zeros without using nonzeros
x=[1 2 2 0 3 1 3 0 0];
i=1;
j=1;
while i <= length(x)
if x(i)==0
x(i) =[] ;
else
x(i)=x(i);
end
while j <= length(x)
if x(j)==0
x(j) =[] ;
else
x(j)=x(j);
end
j=j+1;
i=i+1;
end
end
x
2 Commenti
Rik
il 2 Set 2019
The code you show is not formatted correctly and it doesn't show an array, x is only a scalar. Are you sure this is what you mean?
Dimitrios Adam
il 2 Set 2019
Modificato: Dimitrios Adam
il 2 Set 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Mathematics in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!