Azzera filtri
Azzera filtri

Need help calculating fixation lengths

3 visualizzazioni (ultimi 30 giorni)
H
H il 19 Mar 2014
Commentato: H il 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?

Risposta accettata

Margreet
Margreet il 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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by