How to combine indexing?
28 次查看(过去 30 天)
显示 更早的评论
Is there an elegant way of combining two indexings to select time points from a long time-series?
I have independent selection criteria :
- marked events (index vector ind_Ev)
- marked artifacted periods (ind_Art)
I would like to combine both to select the elements of a time series with 500000 elemtents, i.e. take the ind_Ev and exclude the ind_Art (ind_Ev & ~ind_Art), however, they can point to the same element, in which case it will be excluded.
Thank you so much,
Markus
0 个评论
回答(1 个)
Sindar
2020-10-10
编辑:Sindar
2020-10-10
There may be a better way, but this should work:
% set up a logical-indexing vector that selects no elements
idx_Ev_not_Art = false(500000,1);
% add all ind_Ev elements
idx_Ev_not_Art(ind_Ev) = true;
% remove all ind_Art elements
idx_Ev_not_Art(ind_Art) = false;
% extract those elements
data_Ev_not_Art = data(idx_Ev_not_Art);
8 个评论
Sindar
2020-10-13
编辑:Sindar
2020-10-13
Oh, I'd assumed you had indices, not logicals. There are faster ways in that case, since you can do the boolean logic directly:
idx_Ev = logical(ind_eV);
idx_period = logical(ind_period);
idx_Art = logical(ind_Art);
% data from either events, periods, or both. No artifacts
data_EvORPer_not_Art = data( (idx_Ev | idx_period) & ~idx_Art );
% data from overlap of both events and periods. No artifacts
data_EvANDPer_not_Art = data( idx_Ev & idx_period & ~idx_Art );
% data from events excluding artifacts, plus periods regardless
data_EvANDPer_not_Art = data( (idx_Ev & ~idx_Art) | idx_period );
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!