Find average of multiples lines
古いコメントを表示
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.
7 件のコメント
Bob Thompson
2018 年 2 月 1 日
I'm a little confused how you have your data organized. Do you have a bunch of single difference/time sets?
[T(1),diff] [T(2),diff2] [T(3),diff3]
Or do you have a set of differences for each time point?
[T, diff diff2 diff3 diff4...]
I'm sure it might be simpler than your problem is, but if you do have the second one, what about taking the average at each time point?
Vince Clementi
2018 年 2 月 1 日
編集済み: Vince Clementi
2018 年 2 月 1 日
Bob Thompson
2018 年 2 月 1 日
Are you trying to look for a single average value for the entire array? I thought you were trying to find an average line from the seven other lines?
Again, just to make sure I understand your organization correctly, your 7x301 is organized such that each row is a diff, and each column is a unique time?
Vince Clementi
2018 年 2 月 1 日
Bob Thompson
2018 年 2 月 1 日
No worries about any confusion, I'm just making sure I understand so I actually answer your question.
Ok, so what about adding a check to each column to confirm how many values exist?
for i = 1:301;
if isnan(array(:,i) ~= 0;
nansum = sum(isnan(array(:,i)));
average = sum(array(:,i))/(7-nansum);
else
average = sum(array(:,i))/7;
end
end
I can't guarantee it will work, but that should go through and check each column for NaN values. It will then add up the number of NaN values and reduce the average you are dividing by for each time slot.
I can't say that gives the actual average of the line, so it might be better to go through and fill in the NaN values with interpolations from their lines. This might help give a better average by having all seven values for each time step.
Vince Clementi
2018 年 2 月 1 日
Bob Thompson
2018 年 2 月 1 日
Let me know if it works, and I can post as an official answer, or if you have some trouble shooting you can post your own answer.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!