필터 지우기
필터 지우기

find function in for loop

조회 수: 4 (최근 30일)
ROBERTA NOCERINO
ROBERTA NOCERINO 2019년 8월 29일
답변: Siriniharika Katukam 2019년 11월 18일
Hi :)
I'm quite new in Matlab but I'm wondering if anyome could help me.
So, I have a list of fixation_onset and fixation_offset both of them with 19.953 columns and a timestamps_s list and I want to exactly do this but for all the columns. So that I will have the intersection between the first the first onset and offset, between the second and so on.
first_fixation_onset = find (timestamps_s >= fixation_onsets(1,:));
first_fixation_offset = find (timestamps_s <= fixation_offsets(1,:));
first_fixation_idx = intersect(first_fixation_onset,first_fixation_offset);
I've tried something like this but an error occurs regarding the usage of >= becasue the matrix dimensions do not agree (even if in the aboce example it worked)
for i_fixation_onsets = 1:length(fixation_onsets);
fixation_onsets_idx (i_fixation_onsets) = find (timestamps_s (:,i_fixation_onsets) >= fixation_onsets(:,i_fixation_onsets));
for i_fixation_offsets= 1:length(fixation_offsets);
fixation_offsets_idx (i_fixation_offsets)= find (timestamps_s (:,i_fixation_offsets) <= fixation_offsets(:,i_fixation_offsets));
end
end
Hope I've been enough clear :)

답변 (1개)

Siriniharika Katukam
Siriniharika Katukam 2019년 11월 18일
Hi
In the below lines of code, you are assigning the output of "find" which is an array of values to an element of "fixation_onsets_idx" which can accommodate a single scalar. Hence you got the error of array mismatch.
for i_fixation_onsets = 1:length(fixation_onsets)
fixation_onsets_idx (i_fixation_onsets) = find (timestamps_s (:,i_fixation_onsets) >= fixation_onsets(:,i_fixation_onsets));
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by