removing zeros from matrix

7 ビュー (過去 30 日間)
Perri Johnson
Perri Johnson 2021 年 12 月 19 日
コメント済み: Perri Johnson 2021 年 12 月 20 日
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 件のコメント
Jan
Jan 2021 年 12 月 19 日
Post the code you have tried and explain "no luck" with details. Then the readers can mention, what the problem is.

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

回答 (1 件)

Jan
Jan 2021 年 12 月 19 日
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 件のコメント
Perri Johnson
Perri Johnson 2021 年 12 月 20 日
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

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by