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!