Mean of Multiple data sets across a time series
23 次查看(过去 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!