Selectively removing null data from matrices
조회 수: 4 (최근 30일)
이전 댓글 표시
I am doing some work with an LED tracker that exports the x,y,and z coordinates to a matlab array for analysis. Basically a subject will undergo a series of "trials" that consist of a basic out and back hand movement. So for a given experiment with 10 trials, I will have three matrices (x,y,z) that are 10xN, with N being the maximum number of coordinates output by the tracker. So if one of the trials has, say 150 data points, I will have a 10x150 matrix. For trials with fewer than 150 data points, 0 is used to fill out the corresponding array. Currently I find the size of individual trials (excluding the 0 values) for my calculation and plotting of velocity data, but is there an easy way to exclude the 0's so that I can do all the trials at once? Most cases I have 200+ trials, which makes a trial by trial analysis tedious. I am familiar with loops, but I cannot figure out a good way way to use them for this application. Any help is appreciated.
댓글 수: 0
채택된 답변
Kelly Kearney
2011년 8월 8일
If this is just for plotting purposes, replacing the trailing 0s with NaNs will serve
If 0 is never a valid output, then
data(data == 0) = NaN;
If some of your real data might be 0, then this will replace only trailing 0's
for ii = 1:size(data,1)
idx = find(data(ii,:) ~= 0, 1, 'last');
data(ii,idx+1:end) = NaN;
end
댓글 수: 0
추가 답변 (1개)
Paul
2011년 8월 8일
댓글 수: 1
Fangjun Jiang
2011년 8월 8일
Please give an example data and explain what result do you expect. You can always simplify your data or use smaller size.
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!