38 views (last 30 days)

Hi All,

Having more trouble than I should finding the average line from 7 records. Each record is basically [T, (a-b)], where T is a common time interval (0:0.1:30) and (a-b) is the difference between two data sets (a-b, a-c, a-d, etc.).

I've designated each "difference" as such: diff, diff2, diff3, diff4, diff5, diff6, diff7. I am easily able to plot all of these records on the same plot. However, each method to find the mean of these lines fails. SO far, I have used mean([diff diff2, etc.],7). How do I go about finding the average for each common time point and then plot that?

Thanks.

Greg
on 1 Feb 2018

Regarding the follow-up question found in the comments (NaN affecting the mean):

Use the 'omitnan' flag of the mean function (R2015a and newer):

%%%I wouldn't use "diff" as a variable name - it's a function

avg = mean([diff1, diff2, diff3, diff4, diff5, diff6, diff7],2,'omitnan');

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530968

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530968

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530971

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530971

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530975

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530975

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530977

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530977

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530982

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530982

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530991

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530991

## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530994

⋮## Direct link to this comment

https://ww2.mathworks.cn/matlabcentral/answers/380232-find-average-of-multiples-lines#comment_530994

Sign in to comment.