MATLAB: Plotting a graph for step length

gaitstep lengthstride

Hi. I have a data set that I need to plot against time. X=time. Y in this case is a step length recorded as '1' for right and '1' for left over the entire trial duration.
I need to plot this step length (left '1' to right '1' connecting line) over time.
I am not a Matlab user so need a guidance with this.
Thank you.

Best Answer

This is a bit much for an introduction to MATLAB.
The code begins by using the find function to determine the indices where ‘SoundLeft’ and ‘SoundRight’ are equal to 1, in ‘LSteps’ and ‘RSteps’ respectively. It then uses the index vectors to determine the times (denoted by the ‘Time’ vector) that the respective steps occur, in ‘LStepT’ and ‘RStepT’ respectively. Since you wanted the time differences between heel-strike for the left and right foot separately, all I then needed to do was the calculate the time differences between the successive heel strikes, and for that I used the diff function for each foot, in ‘LStepL’ and ‘RStepL’. Those are one element shorter than the corresponding ‘LStepT’ and ‘RStepT’, necessitating the (1:end-1) subscripts in the plot call. [The EDIT is this explanation, since you mentioned this was your first time using MATLAB.]
See if this does what you want:
[Time,Avatar_On,Sound_On,Sequenceindex,Condition,Treadmillpos,Treadmilltime,Treadmillspeed,SoundLeft,SoundRight,Avatar1pos,Avatar2pos,Avatar3pos,Action,AvatarSpeed,time,timespeed] = ImportAvatar0007('Avatar0007.txt',2, 33118);
LSteps = find(SoundLeft == 1);
RSteps = find(SoundRight == 1);
LStepT = Time(LSteps);
LStepL = diff(LStepT);
RStepT = Time(RSteps);
RStepL = diff(RStepT);
figure(1)
plot(LStepT(1:end-1), LStepL)
hold on
plot(RStepT(1:end-1), RStepL)
hold off
grid
xlabel('Time')
ylabel('Step Length (s)')
legend('Left', 'Right', 'Location','NE')
The code for the function MATLAB created to read your file (using textscan) is attached for you to use. My code requires it because I refer to the variables it creates.