# How to list group names on resampled points after splitapply?

2 views (last 30 days)
Daniel Goldstein on 7 Jan 2022
I'm working with a drilling dataset. The rate of penetration 'rop' is acquired non-uniformly and recorded as a depth (in meters) for different holes.
I've been able to uniformly sample nonuniformly collected sample points through splitapply using the resample function then combine back into a table of the resampled depths and rop values. However, the hole names are needed based on the new resampled points.
How can the group names used for splitapply (e.g. hole names or 'holeid') be re-listed after the resampling? Or objectively speaking, how to get the holeid's listed in the final 'resampledholes' table to analyse by hole?
This is a simplified example with only two holes '12' and '13'...
holeid = [12;12;12;12;12;12;12;12;12;12;12;12;12;12;12;12;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13;13];
depth = [0;0.0542;0.0801;0.2222;0.3959;0.4572;0.5110;0.5348;0.5712;0.6099;0.6437;0.6799;0.8011;0.8928;0.9590;1.0110;0;0.0432;0.1334;0.2483;0.4087;0.4443;0.5009;0.5567;0.5890;0.6253;0.6923;0.7274;0.7588;0.8296;0.8623;0.8955;0.9272;0.9652;0.9959;1.0218];
rop = [118.7000;207.8000;139.6000;176.0000;177.8000;229.3000;242.4000;138.9000;85.7000;140.8000;164.5000;125.4000;189.8000;164.0000;118.4000;211.4000;148.8000;227.9000;14.6000;220.1000;177.2000;226.0000;144.5000;114.2000;157.8000;207.8000;242.5000;247.5000;238.7000;245.7000;241.4000;244.7000;235.6000;242.7000;239.1000;226.0000];
fs10 = [10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10;10];
holes12and13 = table(holeid,depth,rop,fs10);
fs = 10;
G = findgroups(holes12and13.holeid);
holenames = unique(holes12and13.holeid);
[y1,ty1] = splitapply(@(r,d)func(r,d,fs), holes12and13.rop, holes12and13.depth,G);
rop = table(y1{:});
depth = table(ty1{:});
rop = [rop.Var1;rop.Var2];
depth = [depth.Var1;depth.Var2];
resampledholes = table(depth,rop)
resampledholes = 22×2 table
depth rop _____ ______ 0 112.92 0.1 169.26 0.2 165.68 0.3 174.99 0.4 194.7 0.5 194.14 0.6 118.92 0.7 152.21 0.8 178.49 0.9 163.01 1 145.43 0 145.21 0.1 111.84 0.2 117.65 0.3 219.21 0.4 189.16
function [y,yt] = func(yg,t,fs);
[ty,tyt] = resample(yg,t,fs);
y = {ty}; yt = {tyt};
end

Simon Chan on 7 Jan 2022
Try this:
[G,name] = findgroups(holes12and13.holeid); % Store the extracted hold id
%
[y1,ty1] = splitapply(@(r,d)func(r,d,fs), holes12and13.rop, holes12and13.depth,G);
rop = table(y1{:});
depth = table(ty1{:});
rop = [rop.Var1;rop.Var2];
depth = [depth.Var1;depth.Var2];
%
resampledholes = table(name(G),depth,rop) % Put the hold id in the 1st column
resampledholes.Properties.VariableNames(1)=holes12and13.Properties.VariableNames(1) % Re-name the VariableName
Daniel Goldstein on 7 Jan 2022
Thanks!

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by