Binning 2 columns and summing 3rd
7 次查看(过去 30 天)
显示 更早的评论
I have three very large datasets of latitude, potential temperature and ozone. I want to binning the data of latitude and potential temperature and according to the bins, I want to sum ozone data and put it into each bins that I have created. I have tried using accumaray which shows me,
"Error using accumarray
First input SUBS must contain positive integer subscripts."
Indeed ozone data contains float numbers.
Am I missing something or what I could not understand.
I am attaching script as under (also pasting the copied script):
I have also attached mat files of the data.
clc;
clear all;
close all;
ozonef = cell2mat(ozone);
poslatf = cell2mat(poslat);
Tpotf = cell2mat(Tpot);
% % %bining the data-
poslatbin = -90:2:90;
Tpotbin = 250:5:380; %%%% I have values in between this range
nposlat = length(poslatbin);
nTpot = length(Tpotbin);
PL = discretize(poslatf, poslatbin);
TP = discretize(Tpotf, Tpotbin);
ozonef(isnan(ozonef))=min(ozonef);
idx = sub2ind([nposlat nTpot], PL, TP);
FO = accumarray(idx, ozonef, [nposlat*nTpot 1], @(x) mean(x));
contourf(PL, TP, FO);
0 个评论
采纳的回答
Cris LaPierre
2022-1-17
编辑:Cris LaPierre
2022-1-17
I would put your data into a table, then use groupsummary to bin and sum the data as you describe. You will find the Access Data in Tables page helpful.
load latitude
load temperature
load ozone
% create table
data = table(latitude,temperature,ozone)
% define bins
poslatbin = -90:2:90;
Tpotbin = 250:5:380;
% create table of binned data
binTbl = groupsummary(data,["latitude","temperature"],{poslatbin,Tpotbin},'sum',"ozone")
6 个评论
Cris LaPierre
2022-1-18
I don't understand the question. My suggestion - make the changes, and just be sure to update the corersponding variable names in the code I shared, and see if it works.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!