Calculate mean from plot of two vectores

1 view (last 30 days)
Márcia Vicente
Márcia Vicente on 19 Jun 2019
Commented: Star Strider on 21 Jun 2019
I am plotting the displacement of the Center of Pressure of the left foot in the sagital plane, so I get the Roll over Shape from every step.
The steps don't have the same lenght and I am having problems getting the mean of the data.
This is my code so far:
%% Orientation matrix shank x Force plate
for i=1:40000
COP_LCS(i,:)=DBforces.left.glob.CoP(i,:)*Rshank_gait_LCS(:,:,i);
end
%% Circular fit left step
% for the left step look at the rto until the rhs
% indices right toe off= rto
% indices right heel strike= rhs
% Local Coordinate System: X-axis: pointing forwards
% Y-axis: pointing right
% Z-axis: pointing upwards
for i=1:length(rto)
plot(COP_LCS([rto(i,:)]:[rhs(i,:)],1),COP_LCS([rto(i,:)]:[rhs(i,:)],3)); axis 'equal'; hold on
end
How can I plot the mean of this data?
  2 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 19 Jun 2019
It would be easier to answer the question, if you frame the question in following way-
  1. What you have?
  2. Expectation results.
Márcia Vicente
Márcia Vicente on 19 Jun 2019
I have a matrix COP_LCS that is 40000x3, and corresponds to the displacement of the center of pressure in the Local Coordinate System.
Then I have the indices of the right toe off and right heel strike in the time series, that are vectores of 161x1. Corresponding of 161 left steps.
Since I am only interested in the stance phase and I want to see the displacement of the COP in the sagital plane, I am plotting like this:
for i=1:length(rto)
plot(COP_LCS([rto(i,:)]:[rhs(i,:)],1),COP_LCS([rto(i,:)]:[rhs(i,:)],3)); axis 'equal'; hold on
end
where I get this:
plot.png
and I want to get the mean of this steps, and to plot it I would like to have something like this:
plot1.png
this is not right though, because the black * correspond to the first step.
But I don't know how to get the mean of it. Every step has a different leght too.
I cannot attach the data, not even in .rar.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 19 Jun 2019
In order to calculate the mean, the y-coordinate data would have to be interpolated to the same x-coordinate values, those spanning the lowest to the highest values of your x-coordinates. Once you have done that, you would use the nanmean function (or mean with the 'omitnan' argument) to get the mean.
The reason to use nanmean is that the y-values of the shorter steps would be NaN outside their normal x-coordinate ranges (the usual result of interp1 if not extrapolation method is specified, and here you do not want to extrapolate), so nanmean would give the correct values for the mean.
So the code would go something like this:
xvals = linspace(min(x), max(x), 1000);
yvals = interp1(x, y, xvals);
ymean = mean(yvals, dim, 'omitnan');
where ‘dim’ is the dimension you want to take the mean with respect to. (We do not have your data, so we cannot determine that.) The ‘ymean’ output should be what you want, defined at every value of ‘xvals’.
  2 Comments
Márcia Vicente
Márcia Vicente on 21 Jun 2019
Thanks for your answer.
I can run the code that you wrote, but first I have to extract the data from the plot, otherwise because is a loop where the size of a1 and a3 is constantly changing I don't know how to get this variables, without extracting them from the plot.
for i=1:length(rto)
a1=(COP_LCS([rto(i,:)]:[rhs(i,:)],1));
a3=(COP_LCS([rto(i,:)]:[rhs(i,:)],3));
plot(a1,a3); axis 'equal'; hold on
end
after I plot the data I did the followed:
%% extract values from graph to an XX and YY cell
% h = findobj(gca,'Type','line')
% xx=get(h,'Xdata')
% yy=get(h,'Ydata')
% Convert cell to matrix
xx= cell2mat(xx');
yy= cell2mat(yy');
%mean from the plot data
xvals = linspace(min(xx), max(xx), 1000);
yvals = interp1(xx, yy, xvals);
ymean = mean(yvals, 3, 'omitnan');
plot(ymean)
then I get this:
mean.png
but I can't plot it together with the rest, because the axis values are different
Star Strider
Star Strider on 21 Jun 2019
Without your data, I cannot suggest an appropriate approach. I have no idea how your data are organised.

Sign in to comment.

Categories

Find more on Line Plots 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!