Effacer les filtres
Effacer les filtres

Need help calculating fixation lengths

3 vues (au cours des 30 derniers jours)
H
H le 19 Mar 2014
Commenté : H le 19 Mar 2014
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?

Réponse acceptée

Margreet
Margreet le 19 Mar 2014
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 commentaire
H
H le 19 Mar 2014
That's perfect. Thanks a lot.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by