Sorting data in one column based on the time stamps in the alternate column
1 回表示 (過去 30 日間)
古いコメントを表示
Krispy Scripts
2016 年 10 月 17 日
コメント済み: Walter Roberson
2016 年 10 月 18 日
In one matrix, one column has data and the column next to it has time stamps. I have another matrix where the first column is start times and the second column is stop times of the interval. I would like to get the data from the first matrix based on the intervals of the second matrix, where the intervals correspond to the time stamps in the first matrix second column. I would like to output the data into a matrix, where the interval data is in individual columns in that matrix.
Does this make sense? I have attached example matrices. So from the first column dataset.mat, I want the data set that corresponds to the interval.mat (3 intervals) and output them into three different columns corresponding to each interval.
0 件のコメント
採用された回答
Walter Roberson
2016 年 10 月 17 日
selected = arrayfun(@(ROW) dataset(dataset(:,2) >= intervals(ROW,1) & dataset(:,2) <= intervals(ROW,2), 1), 1:size(intervals,1), 'Uniform', 0);
if all(diff(cellfun(@length, selected)) == 0)
selected = horzcat( selected{:} );
else
fprintf('the intervals select different number of rows, had to leave selected as a cell array\n');
end
5 件のコメント
Walter Roberson
2016 年 10 月 18 日
I would need to recheck the code for the case where there was only one interval
Okay I checked and the code will work for that case.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!