find function in for loop

6 次查看(过去 30 天)
ROBERTA NOCERINO
ROBERTA NOCERINO 2019-8-29
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
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