Bonjour à tous,

Je travaille depuis quelques jours sur un script me permettant d'analyser les données relatives à l'enregistrement de mouvements humains (coordonnées XYZ enregistrées à 240Hz). Les enregistrements sont composés de 2 actions du bras droit (chacune vers une cible différente). Dans le script, la distinction entre ces deux actions se fait à l'aide de la seconde boucle 'for'. Ces actions seront répétées 5 fois et enregistrées dans 5 fichiers txt distincts (première boucle 'for').
Pour chaque action, je dois calculer: la vitesse maximal, le temps pour atteindre la vitesse maximal, le début de l'action, la fin de l'action et le temps total de mouvement. Ces valeurs doivent d'abord être calculée pour chaque itération des 2 actions (pour chaque fichier texte). Ensuite, je devrais moyenner les performances aux 5 répétitions.

Je joins une copie du script. Je m'excuse à l'avance si c'est un peu brouillon, je débute en programmation. Il se peut qu'il y ait quelques erreurs ci et là ... (je ne serai pas ici si ce n'était pas le cas )

Mes questions sont les suivantes:
  • Je peine à écrire la formule pour avoir le temps auquel l'action se termine. J'ai besoin du temps relatif au début de l'essai et non de l'enregistrement complet. J'ai déjà écrit quelque chose mais il doit y avoir une erreur quelque part. Lorsque je lance le script, j'obtiens le message d'erreur suivant:
    ??? Subscripted assignment dimension mismatch. 
    Error in ==> Sujet_conditions at 78 
    allendmovement(stim,i) = movementend{stim};
    . Je trouve ça étonnant vu qu'une formule similaire fonctionne parfaitement pour le calcul du temps du début du mouvement. Des suggestions ?
  • Aussi, est-ce correct d'extraire le contenu de 'cell arrays' pour les ré-inscrire dans une matrice (qui sera plus facilement exportable vers un programme d'analyse statistique) ?


Merci d'avance pour l'aide éventuelle !

CL

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
clear all, close all
 
for stim= 1:5;
    data{stim} = load(sprintf('C%02d.txt', stim));
 
    trialtype{stim} = data{stim}(:,1);
 
    %Separates each coordinate in a separate variable
    sx{stim} = data{stim}(:, 2);
    sy{stim} = data{stim}(:, 3);
    sz{stim} = data{stim}(:, 4);
 
    %Define the paramaters required for the butterworth filter
    cutoff = 20;
    samplerate = 240;
    Wn = cutoff/(samplerate/2);
    [B,A]= butter(2, Wn);
 
    %apply the butterworth filter to each coordinate independantly
    sx_filt{stim}= filtfilt(B,A,sx{stim});
    sy_filt{stim}= filtfilt(B,A,sy{stim});
    sz_filt{stim}= filtfilt(B,A,sz{stim});
 
    %take the derivative(velocity) of each coordinate separately
    sx_vel{stim}= [0; diff(sx_filt{stim})./(1/240)];
    sy_vel{stim}= [0; diff(sy_filt{stim})./(1/240)];
    sz_vel{stim}= [0; diff(sz_filt{stim})./(1/240)];
 
    %calculate the overall tangential velocity for the filtered data +
    %defines a timing variable "frame"
    frame{stim}= 1:(size(data{stim}));
    frame{stim}=frame{stim}';
    frame{stim}= (frame{stim} - frame{stim}(1)) ./240;
    velocity{stim} = sqrt((sx_vel{stim}.^2)+(sy_vel{stim}.^2)+(sz_vel{stim}.^2));
    data1{stim}=[frame{stim},velocity{stim},trialtype{stim}];
 
    %calculate different variables for each condition independantly
    for i= 1:2
 
        Condition{stim} = data1{stim}(:,3)==i;
 
        %defines the peak of velocity for condition 1 & 2
        peak_vel{stim}= max(velocity{stim}(Condition{stim}));
 
        %find when the velocity reaches 5% of the peak velocity and defines
        %movementstart as the time when the specified velocity is reached
        start{stim} = find (velocity{stim}(Condition{stim}) > 0.05*max(velocity{stim}(Condition{stim})),1);
        movementstart{stim} = data1{stim}(start{stim},1);
 
 
        %end of the movement is the first time the velocity goes below 5% of peak (after passing 50% of the peak velocity).
        half{stim} = find (velocity{stim}(Condition{stim}) > 0.5*max(velocity{stim}(Condition{stim})),1);
        passedhalf{stim} = data1{stim}(half{stim},1);
 
        endt{stim} = find (velocity{stim}(half{stim}:end,:)< 0.05*max(velocity{stim}(Condition{stim})))+ (half{stim}-1);
        movementend{stim} = data1{stim}(endt{stim},1);
 
        %total movement time
        movementtime{stim} = movementend{stim} - movementstart{stim};
 
        %create an index to find when the peak velocity is reach (should
        %relative to movement start and not to the start of the trial.
        %Hence, the substraction of movementstart{stim}.
        ttpv{stim} = find (velocity{stim}(Condition{stim}) == max(velocity{stim}(Condition{stim})),1);
        timetopeakvel{stim} = data1{stim}(ttpv{stim},1);
 
        %create matrices summarizing all the variables collected in cell
        %arrays
        allpeak_vel(stim,i) = peak_vel{stim};
        alltimeto(stim,i) = timetopeakvel{stim};
        allstartmovement(stim,i) = movementstart{stim};
        allpassedhald(stim,i) = passedhalf{stim};
        allendmovement(stim,i) = movementend{stim};
        allmovementtime(stim,i) = movementtime{stim};
    end
end