find function in for loop

7 ビュー (過去 30 日間)
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));
Hope I've been enough clear :)

回答 (1 件)

Siriniharika Katukam
Siriniharika Katukam 2019 年 11 月 18 日
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));


Community Treasure Hunt

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

Start Hunting!

Translated by