nanmean problem (bachelor thesis help!)

3 views (last 30 days)
Hi!
I'm writing a script where I'm analysing gait data. I calculated the stride velocity by dividing stride length by stride time and it gives me the velocityL vector with some NaN where the SD is greater than 2 times the mean.
Now I wanna delete any wrong values that were created by calculating the velocityL. Because there are NaN is the vector, I used nanmean:
% %remove wrong values
% VelocityL(VelocityL>(nanmean(VelocityL)+SD*nanstd(VelocityL)))= NaN;
However, matlab says that nanmean(VelocityL) is inferior, so the script above won't work.
Does anyone know the solution to my problem?
Thanks in advance! Rik

Accepted Answer

Image Analyst
Image Analyst on 31 May 2015
All your code is in comments so it won't generate any error at all. And, what is the value of SD? Is it 2? What is the values in VelocityL? Without these we can't run your code and recreate your error. You didn't even paste in the error so we don't know what it said. Please copy and paste in all the red text that you see from the error message back here so we can decipher it.
  2 Comments
D.T. van der Meulen
D.T. van der Meulen on 2 Jun 2015
Thanks for your reply.
Indeed, SD = 2. The values in VelocityL are like this:
Inf
3,56453829563124
NaN
NaN
NaN
NaN
NaN
NaN
0,409564278065197
0,557640201673890
NaN
0,614743629694066
0,685943864947752
0,788112282608062
0,731369659147766
0,861933814298274
It says that nanmean(VelocityL) = inf.
This is probably because the array starts with inf. Does anyone know how to fix this?
Image Analyst
Image Analyst on 2 Jun 2015
VelocityL = [...
Inf
3.56453829563124
NaN
NaN
NaN
NaN
NaN
NaN
0.409564278065197
0.557640201673890
NaN
0.614743629694066
0.685943864947752
0.788112282608062
0.731369659147766
0.861933814298274]
% Remove inf from the array.
VelocityL(VelocityL== inf) = [];
% Now get means of non-nan values.
meanV = nanmean(VelocityL)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!