- What you have?
- Expectation results.
Calculate mean from plot of two vectores
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
KALYAN ACHARJYA
el 19 de Jun. de 2019
It would be easier to answer the question, if you frame the question in following way-
Respuestas (1)
Star Strider
el 19 de Jun. de 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 comentarios
Star Strider
el 21 de Jun. de 2019
Without your data, I cannot suggest an appropriate approach. I have no idea how your data are organised.
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!