Binning 2 columns and summing 3rd
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Vaidehi Joshi
il 17 Gen 2022
Modificato: Vaidehi Joshi
il 18 Gen 2022
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 Commenti
Risposta accettata
Cris LaPierre
il 17 Gen 2022
Modificato: Cris LaPierre
il 17 Gen 2022
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 Commenti
Cris LaPierre
il 18 Gen 2022
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!