Binning 2 columns and summing 3rd
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vaidehi Joshi
el 17 de En. de 2022
Editada: Vaidehi Joshi
el 18 de En. de 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 comentarios
Respuesta aceptada
Cris LaPierre
el 17 de En. de 2022
Editada: Cris LaPierre
el 17 de En. de 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 comentarios
Cris LaPierre
el 18 de En. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!