How to combine indexing?

조회 수: 28 (최근 30일)
Markus Gschwind
Markus Gschwind 2020년 10월 10일
편집: Sindar 2020년 10월 13일
Is there an elegant way of combining two indexings to select time points from a long time-series?
I have independent selection criteria :
  1. marked events (index vector ind_Ev)
  2. 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

답변 (1개)

Sindar
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
Markus Gschwind
Markus Gschwind 2020년 10월 13일
>> That error suggests that your ind_Ev is not a set of indices (1,2,40,etc.). More likely than it being a numeric logical vector (0 1 1 0 0 1) is that something else has gone wrong. Can you print the first 10 elements and comment here?
Yes, you were right! It was not [1,3,120,400 etc.] but [1 0 0 1 0 0 0 0 etc.]. When using the first it works without "logical", when using the second, I need "logical".
Sindar
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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by