Selectively removing null data from matrices
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Kelly Kearney
on 8 Aug 2011
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 Comments
More Answers (1)
Paul
on 8 Aug 2011
1 Comment
Fangjun Jiang
on 8 Aug 2011
Please give an example data and explain what result do you expect. You can always simplify your data or use smaller size.
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!