loss of data/missing elements in array after a for loop

조회 수: 2 (최근 30일)
Enzo
Enzo 2023년 4월 28일
댓글: Enzo 2023년 4월 28일
Hello everyone,
I experienced a loss of data when comparing my input and ouput matrices.
for ch=1:32
TD_32_denoise_post_single_chan = TD_32_colon(:,ch);
[val_rms, idx_rms] = findpeaks(-TD_32_denoise_post_single_chan', ...
MinPeakHeight=mat_thr_filt_dat(ch));
idx_matrix_bool_mat_filt(idx_rms,ch) = true;
end
TD_32_colon is a 2584386x32 matrix
idx_matrix_bool_mat_filt is a 2584128x32 matrix
the total loss of data points is 258x32
I do not know where these points are located, and this issue prevents me from performing any operation as I get weird results.
Do you have any suggestion?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2023년 4월 28일
편집: Fangjun Jiang 2023년 4월 28일
If you don't pre-allocate idx_matrix_bool_mat_filt, this could happen. Do idx_matrix_bool_mat_filt=TD_32_colon before the loop.
clear c
a=rand(1,10);
index=find(a>0.5);
c(index)=true
c = 1×5 logical array
0 0 1 0 1
  댓글 수: 1
Enzo
Enzo 2023년 4월 28일
it worked smoothly. Thanks for your help. Really appreciated

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by