You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Plotting a graph for step length
23 views (last 30 days)
Show older comments
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
Chad Greene
on 8 Oct 2014
It's hard to understand exactly what you're asking. Can you provide us with some data? Can you provide a picture (can be drawn in MS Paint, or a photo of a hand drawing) of the final plot you want to create?
Kedar
on 11 Oct 2014
Hi Chad,
Thank you for your reply and apologies for the delay. I am attaching a data set file. I wanted to plot step length (y-axis) against time (x-axis). The action column is the spike of the various phases of my trial.
Hope this helps. Thank you again. I really appreciate you support.
Star Strider
on 11 Oct 2014
‘I am attaching a data set file.’
Still waiting for it to appear...
Star Strider
on 11 Oct 2014
It uploaded. I saved it and read it successfully. What columns should we be looking at?
What do you want us to do with the data?
Star Strider
on 11 Oct 2014
Plotting the steps (R & L) as functions of time is easy.
How do you define step length?
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.
Accepted Answer
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
on 12 Oct 2014
My pleasure!
I doubt if med school will teach you anything at all about MATLAB. I learned FORTRAN as an undergraduate (chemistry major), and had nothing at all about technology in med school. I went back to get a M.S. in Biomedical Engineering after I earned my M.D., completed my residency, and got my Board Certification in Internal Medicine, in order to correct for my deficient knowledge of technology, mathematics, and statistics. In the U.S., the M.D. is not a research degree, and I suspect the same is true in Canada, so it alone will not give you a sufficiently robust background to do research. Your studies will be entirely clinical. (That is actually necessary, because of the volume and complexity of what you will be studying.) If you want to remain involved in research, I would advise you to take one of two paths: do essentially as I did, in the same order (possibly going for a Ph.D. rather than stopping with a M.S.), or do an M.D.-Ph.D. program (something I considered). You will need specialty Board Certification, so be sure to accomplish that. This is not easy, but it is definitely worthwhile.
I look forward to hearing from you.
Kedar
on 13 Oct 2014
Hey thanks man. The script works perfectly. Apologies for the late rely. I am from India and yes med school there is very clinical. I am presently doing my PhD.
Hey any chance I could ask you more questions?
Thanks a lot.
Star Strider
on 13 Oct 2014
I will be glad to consider your questions, and answer them if possible.
With a Ph.D., you will likely be ahead of others in you medical school class in terms of knowledge and experience.
Since my script works as you want it to, I would very much appreciate it if you would Accept my Answer.
Star Strider
on 13 Oct 2014
Edited: Star Strider
on 13 Oct 2014
My pleasure!
Not stupid at all! I’ve been suggesting that MathWorks make it more obvious, as well as change the direction to a ‘down’ arrow, pointing to the particular Answer.
It’s up at the top of my Answer, next to Ursula, my polar bear avatar.
Kedar
on 14 Oct 2014
Edited: Kedar
on 14 Oct 2014
Hi,
Thanks for everything. The file I send was a CAREN software file that records the exposure given to a participant. This file attached now the gait parameters extracted (from the preexisting scripts) from the participant while walking. The recording frequency for this motion capture system is 120Hz while that for previous file is 300Hz, however, it never run at 300Hz and gives a variable frequency between 15-20Hz. Now I want to plot the participants step length over the previous plot (derived from the script above). For that I will have to plot the power spectrum for the Caren file (one with the variable frequency) and determine the peak frequency. Use that to intrapolate both the files to have some number of points before I plot them. Am I right?
Star Strider
on 14 Oct 2014
Who is Chad?
Is this intended for me?
Star Strider
on 14 Oct 2014
What columns do you want me to look at? What are they?
(I would still appreciate your Accepting my Answer, since we resolved your first Question.)
Star Strider
on 16 Oct 2014
When I loaded your file with this call:
[d,s,r] = xlsread('Trial01.xls');
I couldn’t decipher the information in the header in the ‘s’ variable. The xlsread function did everything correctly. I have no idea what the column labels mean and what columns to load and work with. I just opened ‘Trial01_Star.xls’ in Excel and I still have no idea what you want to do.
It might be best for you to extract only the data you want to work with to a separate Excel file and upload it here rather than all your data. If you do that in a consistent format, it will be easier to write code to extract only the data of interest. Meanwhile, knowing what column numbers you want me to work with would be helpful to start. What variables do they represent? What do you want me to do with those data? Please make your data easier for me to understand.
You can Accept my Answer by clicking on the green Accept this answer just to the right of where you clicked to vote for it. Thanks for the vote, too!
Kedar
on 16 Oct 2014
Edited: Kedar
on 16 Oct 2014
Ok. Apologies for this confusion and error. I have given you only the columns that are necessary now. They are step time (time taken to make left step and similarly for right step), step distance (distance covered by that step in the given time) and absolute start time (time for the whole trial). These three columns are for left and right leg. These parameters are derived from motion capture system using other Matlab scripts. The recording frequency for this motion capture system is 120Hz and all values are in mm for distance and seconds for time.
Like previously we plotted step length for avatar from the other file, I want to plot the step length (of the participant) from this attached file over time (x-axis). However they have different frequency of recording. I guess I will have to put in an interpolation (intrep1) function to have same no. of recording points over that time duration and than plot these 2 step length (avatar and the participant). Hope it is a bit clear. Sorry about that.
Also regarding 'accept this answer', there is not place to do that. I saw that option in the other to fellows who provided me some guidance on plotting. I am attaching a screenshot, to help us with that.
Thanks a lot.
Star Strider
on 16 Oct 2014
The ‘Accept’ being absent is interesting, since it actually shows up on my page. Maybe using Firefox as your browser would show it? I may ask a friend with the appropriate privileges to do it.
Thanks for the simplified file. The Right Leg Parameters are displaced down one row from the Left Leg Parameters, but I guess that is not a problem. All we need to do is plot step_t for the right and left, correct? If the times are correct, and all we’re interested in are the times between steps, the sampling time may be irrelevant. Also, step_d seems to be the same (distance difference between heel strikes) as step_t is for time. Are we doing anything with it or can I ignore it for now?
Late here — I’ll work on this in the morning.
Kedar
on 16 Oct 2014
Hey no problem. Work when you are have some time. I will try with firefox about it.
Yes I had done the same thing. If I plot the gait parameters over time, it shouldn't matter if we the recording frequency is different. I tried to explain this to superiors but they don't seem to get it. I am tired explaining this.
The left leg parameters are displaced on row as the participant possibly stopped walking with that step. Well I guess we don't use step_d as of now. Lets plot right and left step length over the previous plot and see how it looks.
Thanks man.
Star Strider
on 16 Oct 2014
My pleasure!
The absolute times and differences are so much grater that the sampling times that small differences in sampling times and frequencies are not going to make any difference at all. This is different if we’re doing signal processing or some such, where sampling times and frequencies are critical. It affects the precision a bit,but your time differences are all about half a second or such, so I doubt that the precision loss is greater than the sampling noise. As I calculate it, it would introduce about <2% error in the time measurements, probably not enough to bother about. The only significance would be if the sampling frequencies were significantly different — like 60 Hz compared to 120 Hz.
All the data are there for both legs. The right leg parameters are displaced one column down from the left leg, so the values in Column A aren’t relevant.
Star Strider
on 17 Oct 2014
I submitted a Bug Report to MathWorks about your not being able to Accept answers (I included your screenshot and the thread URL), and apparently they accepted it for you. I haven’t heard from them directly yet, but at least they know of the problem.
This works with ‘Trial01_Star.xls’:
[d,s,r] = xlsread('Trial01_Star.xls');
D = d(:,[4 2 8 6]);
figure(1)
plot(D(:,1),D(:,2),'-b', D(:,3),D(:,4),'-r')
grid
xlabel('|Time| (s)')
ylabel('Step Length (s)')
legend('Left', 'Right')
You already calculated the step length apparently, so all I needed to do was to figure out what was in the columns xlsread imported, reallocate them to my ‘D’ array, and plot. (I didn’t plot distance, since you are apparently not working with it at this point.)
This should work as written.
Star Strider
on 12 Nov 2014
No message. It’s best to keep everything on MATLAB Answers anyway. I generally don’t reply to PMs.
Kedar
on 24 Nov 2014
Hi. No problem. Sorry about that. I just wanted to say that I had some other problem so I didn't check the matlab answers, sorry for the inconvenience.
I was just trying another script and this error came up. I am attaching a screenshot it. Any suggestions on how to resolve this.
Star Strider
on 24 Nov 2014
I don’t see the screenshot. Where did you put it?
Image Analyst
on 25 Nov 2014
What does "whos info" tell you? Or just look at it in the workspace. Is info 9 characters long? Probably not.
Star Strider
on 25 Nov 2014
I A — Thank you.
Kedar — I don’t know where you’re sending the messages. They’re not appearing in anything I use. (I discourage individual messages from MATLAB Answers.)
Star Strider
on 25 Nov 2014
The screenshot came through previously. We still don’t know the size of |‘info’.
Star Strider
on 25 Nov 2014
Type this in the Command Window:
whos info
Specifically note ‘Size’ and ‘Class’.
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
on 28 Nov 2014
You need to create ‘info’ and put something in it. (Empty variables can occasionally cause problems.)
More Answers (1)
Kedar
on 5 Dec 2014
Edited: Kedar
on 5 Dec 2014
Hi,
How to convert .c3d to .mat file?
1 Comment
Star Strider
on 5 Dec 2014
I’ve not a clue.
See The 3D Biomechanics Data Standard and particularly MATLAB Toolbox For C3Dserver – Version 2 for information.
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.
See Also
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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)