필터 지우기
필터 지우기

Problems with indexing into an array with nan (indexing on 2 variables)

조회 수: 4 (최근 30일)
PAK
PAK 2018년 8월 23일
댓글: PAK 2018년 8월 30일
Hi All,
I'm having trouble using a logical variable ( Bandphase_logical = 9x5272240 logical) to find "true" events in another variable ( bandphase = 3x5272240 single). I think part of my problem is that the "bandphase" variable contains NaNs and I am trying to index over 2 different variables (see below).
"Bandphase_logical" contains 1's where an event occurs across a time series (5272240 samples). "bandphase" contains radian values across the entire timeseries (5272240 samples). Each row contains different frequency bands, and has a "NaN" where that sample does that have a frequency.
I'd like to do something along the lines of (I'd to create a loop where the bandphase variable changes adaptively with how many rows it has and same with the Bandphase_logical variable [e.g.: if bandphase had 5 rows and Bandphase_logical had 12 rows]):
bandphase(1,:)(Bandphase_logical(1,:)
bandphase(1,:)(Bandphase_logical(2,:)
.
.
bandphase(1,:)(Bandphase_logical(9,:)
bandphase(2,:)(Bandphase_logical(1,:)
bandphase(2,:)(Bandphase_logical(2,:)
.
.
bandphase(2,:)(Bandphase_logical(9,:)
bandphase(3,:)(Bandphase_logical(1,:)
bandphase(3,:)(Bandphase_logical(2,:)
.
.
bandphase(3,:)(Bandphase_logical(9,:)
I'd greatly appreciate any help! I'm thoroughly confused.
PK

채택된 답변

Stephen23
Stephen23 2018년 8월 23일
편집: Stephen23 2018년 8월 23일
for ii = 1:size(bandphase,1)
for jj = 1:size(Bandphase_logical,1)
tmp = bandphase(ii,:);
tmp(Bandphase_logical(jj,:))
end
end
To store the output (of different sizes) use a cell array:
S = [size(bandphase,1),size(Bandphase_logical,1)];
C = cell(S);
for ii = 1:S(1)
for jj = 1:S(2)
tmp = bandphase(ii,:);
C{ii,jj} = tmp(Bandphase_logical(jj,:))
end
end
You can download padcat to automatically pad with NaN's and create one numeric array:
mat = padcat(C{:})
  댓글 수: 5
Stephen23
Stephen23 2018년 8월 23일
@PAK: see my edited answer.
PAK
PAK 2018년 8월 30일
This was amazing. Thank you!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by