Subsetting equal data from a array to different arrays

2 vues (au cours des 30 derniers jours)
Jeroen Platteeuw
Jeroen Platteeuw le 1 Avr 2015
Modifié(e) : per isakson le 2 Avr 2015
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 commentaire
Stephen23
Stephen23 le 1 Avr 2015
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.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 1 Avr 2015
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,:)});
  1 commentaire
Jeroen Platteeuw
Jeroen Platteeuw le 2 Avr 2015
Dear Andrei
It works fine, thank you.
Kind regards,
Jeroen

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by