- What you have?
- Expectation results.
Calculate mean from plot of two vectores
3 次查看(过去 30 天)
显示 更早的评论
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
It would be easier to answer the question, if you frame the question in following way-
回答(1 个)
Star Strider
2019-6-19
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 个评论
Star Strider
2019-6-21
Without your data, I cannot suggest an appropriate approach. I have no idea how your data are organised.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!