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 Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by