Mean of Multiple data sets across a time series
12 ビュー (過去 30 日間)
古いコメントを表示
I have 5 sets of CO2 concentrations, all taken at different locations. They have different start dates, the earliest beginning in 1957 and the latest in 1981 all up until the present. I would like to find the average of all 5 locations to create one line and be able to plot it against time, I believe this would take a for loop which I am not very experienced in. I also considered keeping the datasets separate and just finding the averages of each and using hold on to plot them against each other, but I again run into the issue of figuring out how to code to loop to keep it against time. If one of these ways would be a better option for how I should analyze my data that would be helpful.
6 件のコメント
Voss
2021 年 12 月 9 日
Yeah, if you can upload the .csv file, that would be perfect.
If you're unable to do so, maybe it's too large? Probably just the top however many rows would be sufficient for me to get an idea of what the data is. If all else fails, maybe a screen shot of the .csv open in Excel or whatever would work well enough.
回答 (1 件)
Aman
2024 年 4 月 18 日
Hi Fiona,
As per my understanding, you want to get the mean CO2 where the reading has been taken at different locations and the time stamp of the recording is also different.
Without the actual data, it is difficult to tell the solution upfront, but I have created a sample example code where I have created a table that contains readings in ppm across different locations and were taken at different months. Now, in order to calculate the mean, I'm getting the reading across the same month and then calculating the mean. You can refer to the below code for your reference.
location = ["A";"A";"B";"B";"B";"C";"C";"D"];
month = ["Jan";"Mar";"Jan";"Feb";"Mar";"Feb";"Mar";"Jan"];
ppm = [10;20;30;40;50;60;70;80];
dataTable = table(location,month,ppm);
dataArray = table2array(dataTable);
uniqueMonths = unique(dataArray(:,2));
for i=1:length(uniqueMonths)
requiredPPM = dataArray(dataArray(:,2)==uniqueMonths(i),3);
monthMean = mean(str2double(requiredPPM));
disp("Mean of " + uniqueMonths(i) + " is " + monthMean);
end
Hope it helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!