MATLAB: Subsetting equal data from a array to different arrays

equal datasubsetunique

Hello, I'm currently working on a overtopping script and now I need to split up my data. I want to go from this data (selecting the rows with the same values in the first two columns):
0.0010 0.0310 NaN 0.5873
0.0010 0.0590 NaN 0.8092
0.0050 0.0310 3.0958 0.7419
0.0050 0.0310 3.8532 0.7570
0.0050 0.0310 6.4800 0.6803
0.0050 0.0310 24.3356 0.6091
0.0050 0.0310 37.2512 0.6321
0.0050 0.0310 37.2633 0.5996
0.0050 0.0310 75.1829 0.6125
0.0050 0.0310 93.9991 0.6680
0.0050 0.0590 2.2801 0.8573
0.0050 0.0590 2.7944 0.8585
0.0050 0.0600 2.7647 0.8750
0.0050 0.0600 18.1790 0.8311
0.0050 0.0600 27.5549 0.8176
0.0050 0.0600 27.6349 0.8064
To this:
Subset1
0.0010 0.0310 NaN 0.5873
Subset2
0.0010 0.0590 NaN 0.8092
Subset3
0.0050 0.0310 3.0958 0.7419
0.0050 0.0310 3.8532 0.7570
0.0050 0.0310 6.4800 0.6803
0.0050 0.0310 24.3356 0.6091
0.0050 0.0310 37.2512 0.6321
0.0050 0.0310 37.2633 0.5996
0.0050 0.0310 75.1829 0.6125
etc.

Best Answer

  • a = [ 0.0010 0.0310 NaN 0.5873
    0.0010 0.0590 NaN 0.8092
    0.0050 0.0310 3.0958 0.7419
    0.0050 0.0310 3.8532 0.7570
    0.0050 0.0310 6.4800 0.6803
    0.0050 0.0310 24.3356 0.6091
    0.0050 0.0310 37.2512 0.6321
    0.0050 0.0310 37.2633 0.5996
    0.0050 0.0310 75.1829 0.6125
    0.0050 0.0310 93.9991 0.6680
    0.0050 0.0590 2.2801 0.8573
    0.0050 0.0590 2.7944 0.8585
    0.0050 0.0600 2.7647 0.8750
    0.0050 0.0600 18.1790 0.8311
    0.0050 0.0600 27.5549 0.8176
    0.0050 0.0600 27.6349 0.8064];
    [~,~,c] = unique(a(:,1:2),'rows');
    out = accumarray(c,(1:numel(c))',[],@(x){a(x,:)});