removing zeros from matrix

조회 수: 5 (최근 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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by