Average Position vs Time Graph?
3 次查看(过去 30 天)
显示 更早的评论
I need to make a position vs time graph with data collected from a subject during walking. I have two variables, 'position' and 'time.' They are both matrices, with the position/time data from each step in its own column (position(x,y) corisponds to time(x,y)). The steps very in duration and the number of postion measurements. I normalized the time so that all steps are the same length. Right now I can produce ~30 lines showing each individual step. I need to average the data and create one line representing all the steps. Whats the best way to do this? I was told to use the spline function to create the graph but having trouble. Thanks ~Dan
2 个评论
Mitch Nyandoro
2018-5-7
Hi Daniel, i hope you managed to solve this problem i am currently working on something similar please assist with code for the position vs time graph if you do not mind
采纳的回答
Walter Roberson
2011-6-11
You have 2D data, but you have not indicated which dimension you wish to average over.
It is not apparently to me why the arrays are 2D for a single subject? If multiple subjects were involved, that would make sense.
Is this really a question about producing "one line" by averaging, or is it a question about producing a smooth line from a list of (X,Y) positions? Producing one line by averaging has no immediately obvious connection to splines.
5 个评论
Laura Proctor
2011-6-13
I'm not sure why your variable for time would be a matrix, generally it will be a vector.
But, if you have all of your position data in one matrix where the rows indicate different positions and the columns are the time steps, you can plot this data as lines against the index values by taking the transpose. For example, suppose your data is contained in a variable named 'A':
plot(A')
will plot the data in each column as one line. Furthermore, if you have a vector of time data, you can plot A against time:
plot(t,A')
更多回答(1 个)
Laura Proctor
2011-6-13
If you know the model that you would like to use, and it is one equation for all of the data, then linear regression would be the way to go.
However, if you simply wish to fit a line or a polynomial, it makes it even easier; you can use the polyfit function. So, for example, say that you have t and x data that you would like to fit with a quadratic, simply type in the command
c = polyfit(t,x,2);
and you will have the coefficients of the best-fit polynomial returned in c. If you want to take it further and plot that polynomial, then use the polyval function like this:
plot(t,polyval(c,t))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Smoothing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!