필터 지우기
필터 지우기

How do I exact all the indexes with a certain value?

조회 수: 3 (최근 30일)
ET
ET 2023년 5월 15일
댓글: ET 2023년 5월 15일
I wrote a loop that scan through the channel that contains all the trigger markers and I set those with intensity >3 to 1, else =0. Now I have this variable (marker) that contains the trigger markers at the intensity of 1. I would like to get the indexes of marker with an intensity of 1. How should I do that? Thanks,
marker = zeros(size(Inpt_RZ2_chn002.dat));
for mi = 1:length(Inpt_RZ2_chn002.dat)-1
if Inpt_RZ2_chn002.dat(mi) > 3
marker(mi) = 1;
else
marker(mi) = 0;
end
end
plot(marker)

채택된 답변

Matt J
Matt J 2023년 5월 15일
편집: Matt J 2023년 5월 15일
Don't use a loop. Just do,
marker = Inpt_RZ2_chn002.dat > 3;
The logical vector marker already functions as an index vector, e.g.,
greaterThanThree = Inpt_RZ2_chn002.dat(marker)
  댓글 수: 3
Matt J
Matt J 2023년 5월 15일
편집: Matt J 2023년 5월 15일
How do I get the indexes of all the ones into a new variable with only all the indexes of ones.
Why are the indices in logical form not enough?
x=(1:5)*10
x = 1×5
10 20 30 40 50
marker=(x>30)
marker = 1×5 logical array
0 0 0 1 1
x(marker)
ans = 1×2
40 50
If you really do need numeric indices, use find()
find(marker)
ans = 1×2
4 5
ET
ET 2023년 5월 15일
Why are the indices in logical form not enough?
I use the indices to epoch eeg data. Thanks Matt

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by