필터 지우기
필터 지우기

Need help calculating fixation lengths

조회 수: 3 (최근 30일)
H
H 2014년 3월 19일
댓글: H 2014년 3월 19일
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?

채택된 답변

Margreet
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
  댓글 수: 1
H
H 2014년 3월 19일
That's perfect. Thanks a lot.

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

추가 답변 (0개)

카테고리

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