removing zeros from matrix

3 vues (au cours des 30 derniers jours)
Perri Johnson
Perri Johnson le 19 Déc 2021
Commenté : Perri Johnson le 20 Déc 2021
Hi,
I've constructed a code looking at vertical force data and have it set to put each stance phase into it's own column. The one issue I'm having is that I have all these extra zeros. Any way to remove them so I don't have to export all of these zeros with the data I care about? Have tried "remove," "nonzeros," and "~=0" functions but with no luck.
Thanks in advance
  1 commentaire
Jan
Jan le 19 Déc 2021
Post the code you have tried and explain "no luck" with details. Then the readers can mention, what the problem is.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 19 Déc 2021
x(x==0) = [];
% Or:
x = x(x~=0);
Where do the zeros come from? Instead of removing them it might be easier to avoid to create them before.
  1 commentaire
Perri Johnson
Perri Johnson le 20 Déc 2021
Up until line 91, t_step becomes a 2694x10 matrix (a lot of the cells are zeros) because each stance phase is seperated by where it occurs over the time duration. when I try, t_step = t_step(t_step~=0); t_step becomes a 1649x1 matrix. I'm trying to keep all of the non zero values so I don't have a huge number of cells with zeros when I export the data.
the zeros come from this for loop that I have set up from lines 66 - 87
for i = 2:length(time)
p = p+1;
if TO == 10 %once the last element is reached, code breaks out of the for loop to prevent error
break
end
if grf_z(i) >= threshold && grf_z(i-1) < threshold
HS=HS+1;
t_RON(HS) = time(i);
f_RON(HS) = grf_z(i);
q = q+1;
elseif grf_z(i) < threshold && grf_z(i-1) >= threshold
TO=TO+1;
t_ROFF(TO)=time(i-1);
f_ROFF(TO)=grf_z(i-1);
end
if grf_z(i)>=threshold
t_step(p,q)=time(i);
f_step(p,q)=grf_z(i);
end
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by