Selectively removing null data from matrices

조회 수: 4 (최근 30일)
Paul
Paul 2011년 8월 8일
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.

채택된 답변

Kelly Kearney
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

추가 답변 (1개)

Paul
Paul 2011년 8월 8일
I understand how you did that, but my problem isn't that an entire column is zero. It's that the matrix dimensions are determined by the largest dataset, and for trials that have fewer data points are filled in with 0's. So if column 1 has the most data points, say, 150, that will set the matrix dimension to 150. If column 2 only has 100 data points, all elements beyond 100 will be set to 0. I want to be able to plot all columns together without the 0 values.
  댓글 수: 1
Fangjun Jiang
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 CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by