Filter löschen
Filter löschen

Need help calculating fixation lengths

3 Ansichten (letzte 30 Tage)
H
H am 19 Mär. 2014
Kommentiert: H am 19 Mär. 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?

Akzeptierte Antwort

Margreet
Margreet am 19 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by