フィルターのクリア

How can I divide a dataset into trials using a specific delimiter?

1 回表示 (過去 30 日間)
samy rima
samy rima 2015 年 6 月 18 日
コメント済み: samy rima 2015 年 6 月 30 日
Hello,
I have a dataset of eye-tracking data that looks like so:
Time X Y
192 15 NaN
499 609 519
499 608 519
. . .
. . .
. . .
1200 800 NaN
1201 750 600
. . .
. . .
. . .
2000 792 NaN
All lines between 2 consecutive NaNs correspond to a trial, I would like to create a cell array where each cell contains all the rows from one trial. Can you help me on how to procede?
Thank you

採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 18 日
nanpos = find(isnan(YourData(:,3))]);
nanruns = diff([1 nanpos size(Yourdata,1)]);
blocks = cell2mat(YourData, nanruns, size(YourData,2));
blocks( cellfun(@isempty, blocks) ) = [];
Each of the blocks in the cell array will now start with a NaN entry, except in the case where the first entry in the array did not have a NaN, in which case the first block will include all the entries before the first NaN. Only the first block has that possibility.
If the last entry in the array is a NaN entry then the last block will be that entry by itself. I did it this way, instead of deleting the NaN, in case the NaN entry has some useful information you want to extract.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 6 月 19 日
nanruns = diff([1; nanpos; size(Yourdata,1)]);
samy rima
samy rima 2015 年 6 月 30 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by