plotting the mean and standard deviation of data when there is more than one piece of data collected at a particular point

3 ビュー (過去 30 日間)
I have a matrix, in one columnn is the day of year and in the other is the data associated with that day of year. On some days of the year there are multiple data points, while others there is one or none. This makes it difficult to plot the information, what I would like to do is plot the data based on the mean and standard deviation of the data. So if data was collected three times on the 320th day of the year then the mean and standard deviation of these three data points would be found out and then when plotted the mean line would go through the mean and the standard deviation would represent error bars. How would I go about this?
Thanks,
Natalie

採用された回答

Natalie
Natalie 2014 年 1 月 24 日
[~,ind,subs] = unique(DOY);
means = accumarray(subs, data, size(ind), @mean); stds = accumarray(subs, data, size(ind), @std);
final = [DOY(ind), means, stds]

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 1 月 22 日
Are you saying that if some day has duplicates, you want to replace them with the mean of the bunch? Like 3 values of 100, 101, and 102 for day #320 would go to only 1 value of 102 for that day?
Why can't you just scan over the days and find out which one has multiples and then delete the unneeded ones? Let's say you found that elements 40,41, and 42 were all for day #320, so you could do
newMean = mean(theMeans(40:42)); % Get new mean
newSD = std(theSDs(40:42)); % Get new SD
% Assign new mean to element 40
theMeans(40) = newMean;
theSDs(40) = newSD;
% Now delete elements 41 and 42 because they are not needed anymore
themeans(41) = [];
theSds(41) = [];
themeans(42) = [];
theSds(42) = [];
  3 件のコメント
Image Analyst
Image Analyst 2014 年 1 月 22 日
Natalie, you don't do it manually. You use a loop. Everything I gave you above could be generalized for any number of measurements per day, not just 3. You just use a loop. You do know how to find if a day has more than one measurement, don't you? If not, try unique() or histc() or something like that.
Natalie
Natalie 2014 年 1 月 22 日
I've been trying to create a loop with this code but it keeps on failing or not providing the right answer. I'm fairly unexperienced in matlab. I've tried many different loops but can't seem to get one to work correctly. Sorry, I'm just not that experienced with loops, how would you go about creating a loop? Here is an example of one of the loops I have tried:
for i= unique(doy_int_sort(:,1));
doy_int_n = mean(i,2);
doy_int_SD = std(i,2);
doy_int_sort(i,2) = doy_int_n;
doy_int_sort(i,3) = doy_int_SD;
end;
I decided not to include the part that deleted the elements because I could do that with unique after I had run the loop.
Thanks,
Natalie

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by