Plotting a graph for step length

33 views (last 30 days)
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.
  8 Comments
Star Strider
Star Strider on 11 Oct 2014
Plotting the steps (R & L) as functions of time is easy.
How do you define step length?
Kedar
Kedar on 11 Oct 2014
Edited: Kedar on 11 Oct 2014
I wouldn't say it is easy. This is possibly my first time to use Matlab. Left step length is defined as distance covered from left heel strike to right heel strike and similarly right side.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 Oct 2014
Edited: Star Strider on 12 Oct 2014
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.
  33 Comments
Star Strider
Star Strider on 26 Nov 2014
That means that ‘info’ doesn’t exist in your workspace.
You need to go through your code to understand the reason. (If you intend to create it in an if block for instance, the if condition may not be met so the block never executes. I’m just guessing here.)
Star Strider
Star Strider on 28 Nov 2014
You need to create ‘info’ and put something in it. (Empty variables can occasionally cause problems.)

Sign in to comment.

More Answers (1)

Kedar
Kedar on 5 Dec 2014
Edited: Kedar on 5 Dec 2014
Hi,
How to convert .c3d to .mat file?
  1 Comment
Star Strider
Star Strider on 5 Dec 2014
I’ve not a clue.
Also see Jan Simon’s File Exchange contribution C3D_VaxD2PC.
You would have to read the file into your MATLAB workspace, then save it as a .mat file.
That’s the best I can do.

Sign in to comment.

Categories

Find more on Historical Contests in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!