Need help calculating fixation lengths
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I am looking to calculate the lengths of fixations on different areas, but I am completely stuck on it. What I need is for my code to only take into account when there are more than three in a row of the same value. So I have the following code:
x = {'d','f','g'}; %areas of interest
r = {'d','d','d','d','d','d','f','f','f','f','g','g','f','f','d','d','d','d','g','g','g','g','f'};
[~,ii] = ismember(r(1:end),x) %Changes from strings to numbers (d=1,f=2,g=3)
I can register the occurrences of every change in area of interest, but I can't seem to get it to ignore the ones that are shorter than 3. So in the above example at: ...'f','g','g','f'... It should ignore the g's, possibly change those g's into zeroes.
Any ideas?
0 个评论
采纳的回答
Margreet
2014-3-19
This seems to accomplish what you ask. I don't know if it is the most elegant solution, though...
clc; clear all; close all;
x = {'d','f','g'}; %areas of interest
r = {'d','d','d','d','d','d','f','f','f','f','g','g','f','f','d','d','d','d','g','g','g','g','f'};
[~,ii] = ismember(r(1:end),x); %Changes from strings to numbers (d=1,f=2,g=3)
constantVar= r(1);
counter=1;
for i = 2:length(r)
tempVariable = r(i);
if (strcmp(tempVariable,constantVar) == 1)
counter = counter+1;
else
if (counter <= 2)
lowerLimit = i- counter;
upperLimit = i-1;
ii(lowerLimit:upperLimit) = 0;
end
counter=1;
constantVar=r(i);
end
end
if (counter <= 2)
lowerLimit = length(r)- counter+1;
upperLimit = length(r);
ii(lowerLimit:upperLimit) = 0;
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!