MATLAB Answers

0

Calculate mean from plot of two vectores

Márcia Vicente さんによって質問されました 2019 年 6 月 19 日 14:01
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 6 月 21 日 11:29
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 件のコメント

KALYAN ACHARJYA
2019 年 6 月 19 日 14:10
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 2019 年 6 月 19 日 18:14
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.

サインイン to comment.

タグ

1 件の回答

回答者: Star Strider
2019 年 6 月 19 日 19:04

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 件のコメント

Márcia Vicente 2019 年 6 月 21 日 10:56
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
2019 年 6 月 21 日 11:29
Without your data, I cannot suggest an appropriate approach. I have no idea how your data are organised.

サインイン to comment.



Translated by