Subsetting equal data from a array to different arrays
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2015-4-1
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.
采纳的回答
Andrei Bobrov
2015-4-1
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,:)});
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numeric Types 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!