フィルターのクリア

Isolating segments of data in one column using time integrals from the next column

2 ビュー (過去 30 日間)
Hi,
I am trying to find segments of data from intervals of start and stop times. The data is a matrix with data in the first column and time stamps in the second column that correspond to the interval times. I would like to get the data in the first column that corresponds to the time stamps in the second column. I would also like the out put interval (there are multiple intervals, in the samples I provided there are 3) to be that each segment is in a separate matrix row or column or even cell array (any is find I just want them to be separate). I have tried some code but am getting empty cell array outputs:
for i=1:numel(interval(:,1))
w=interval(i,:);
output{i}=intersect(data(find(data>=w(1))),data(find(data<=w(2))));
end
I have attached an example of data in a matrix data and intervals in matrix interval. Any help would be wonderful.

採用された回答

dpb
dpb 2017 年 6 月 12 日
Logical addressing to the rescue!!! :)
>> for i=1:length(interval)
c{i}=data(iswithin(data(:,2),interval(1,1),interval(1,2)),:);
end
>> whos c
Name Size Bytes Class Attributes
c 1x3 336180 cell
>> c{1}(1:5,:)
ans =
-0.1134 62.6188
-0.1084 62.6198
-0.1103 62.6208
-0.0544 62.6218
-0.0191 62.6228
>>
iswithin is my "syntactic sugar" utility routine--
>> type iswithin
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
>>
You can collapse the loop via arrayfun; whether it's any faster or not is probably iff--
>> arrayfun(@(i1,i2) data(iswithin(data(:,2),i1,i2),:), ...
interval(:,1),interval(:,2), ...
'uniformoutput',0)
ans =
[7000x2 double]
[7000x2 double]
[7000x2 double]
>>
  1 件のコメント
Krispy Scripts
Krispy Scripts 2017 年 6 月 13 日
Thank you!! Yes, I figured I need to use logical addressing, but was having problems using it to find corresponding values in a matrix

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by