Subsetting equal data from a array to different arrays

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.

1 Comment

Although you give some nice input data, your explanation is not clear what output you require, and we can't read minds. Please show the exact output that you would expect from this input data.

Sign in to comment.

 Accepted 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,:)});

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!