필터 지우기
필터 지우기

Average Position vs Time Graph?

조회 수: 3 (최근 30일)
Daniel
Daniel 2011년 6월 11일
댓글: Mitch Nyandoro 2018년 5월 7일
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
Daniel
Daniel 2011년 6월 13일
I worked on it over the weekend but still can't figure it out... Any ideas?
Mitch Nyandoro
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
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
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')
Daniel
Daniel 2011년 6월 14일
Walter...
I tried the code you provided (at least as I understand it) and received the following error:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> linspace at 22
y = [d1+(0:n-2)*(d2-d1)/(floor(n)-1) d2];
I tried several variations but received errors like:
??? Error using ==> polyfun\private\chckxy at 25
X must be a vector.
Error in ==> spline at 55
[x,y,sizey,endslopes] = chckxy(x,y);
I feel like this should be a very simple task but am having a very hard time making headway. I asked my lab for help... below is a copy of code I was given from my lab. Apparently it was used by the people that use to do the gait analysis. This is all the code I received.
N_sp =100; % desired number of samples
t_raw = 0:N_raw-1; % an example of original time set:
% (N_raw - original number of frames)
t_sp = 0: N_raw-1/(N_sp-1): N_raw-1; % desired time set
new_data = spline(t_raw,old_data,t_sp);
Any ideas?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Laura Proctor
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))
  댓글 수: 8
Daniel
Daniel 2011년 6월 13일
I'm sorry, I should have stated that earlier... I DO NOT need an equation of the line.
I normalized the 'Time' data... the line 'tt = linspace(t(1),t(end),1e3);' is used to smooth the line?
xx = spline(t,x,tt);
Where t='time', x='position' and tt=smoothness of the line. I will then graph: 'plot(tt, xx)'?
Let's say that I'm trying to plot 30 steps and each step has 20 to 40 recorded positions (varies depending on the length of the step). My variables for time and position will have 30 columns with 20 to 40 rows. Will it be able to process the variables as matrices?
Daniel
Daniel 2011년 6월 14일
Laura...
You were right. I needed to make 'time' a vector. Still having some problems but making progress.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spline Construction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by