沿第三维排序3D阵列

时间:2016-04-20 14:09:37

标签: matlab sorting

我在 test1 = input("String1: ") test2 = input("String2: ") common = {} if len(test1)<len(test2): for letter in test1: if letter in test2: common[letter]= 1 else: for letter in test2: if letter in test1: common[letter]= 1 print (len(common)) 中存储了144x91x92矩阵。我想查看第三个维度(代表一个季节中的日子)并对其进行排序。然后,我想提取值的前10个和后10个百分位,包括这些值的索引。这将找到每个网格单元的前10个和后10个百分位数(对于每个网格单元,这将是不同的。)

我正在尝试以下方法:

o3{1}

但我知道我并没有将前10名和后10名百分位数排除在外。另外,这种方式并没有告诉我最高和最低10个百分位天数的指数(每个144x91网格单元格不同)。我希望以最高10个百分点的天数,最低10%的天数以及每个天数的指数结束144x91x10矩阵。

2 个答案:

答案 0 :(得分:1)

试试这样:

[~, I] = sort(o3{1},3); %// sort o3 along 3rd dimension
ind_top10 = I(:,:,end-8:end);
ind_bot10 = I(:,:,1:9);

I3 = cat(3, ind_top10, ind_bot10); %// you might want to skip this but and just work with the top and bottom separately from here on

[I1, I2, ~] = ndgrid(1:size(o3{1},1), 1:size(o3{1},2), 1:size(I3,3));
ind = sub2ind(size(o3{1}),I1,I2,I3)

现在

o3{2}(ind)
o3{3}(ind)
%// etc...

答案 1 :(得分:1)

这与what Dan had suggested

略有不同
%% // Init
clear variables; clc;

%% // Generate some data:
o3 = cell(3,1);
for indO = 1:3
  o3{indO} = randi(intmax('uint16'),144,91,92,'uint16');
end

%% // Find 10 & 90 percentiles:
percentiles = cat(3,prctile(o3{1},10,3),prctile(o3{1},90,3));

%% // Find indices of relevant values
select_bot10 = bsxfun(@ge,o3{1},percentiles(:,:,1)); %// replace @ge with @gt if needed
select_top10 = bsxfun(@le,o3{1},percentiles(:,:,2)); %// replace @le with @lt if needed
%// Another optional way to index the values if required:
[rb,cb,vb] = ind2sub(size(select_bot10),find(select_bot10));
[rt,ct,vt] = ind2sub(size(select_top10),find(select_top10));

%% // Get values from o3{1..3} etc.
bot10 = o3{1}(select_bot10);
top10 = o3{1}(select_top10);
%// etc.

此解决方案可能不适合您的特定需求,但调整应该是直截了当的。另请注意,由于精确百分位数,因此bot10top10之间元素的数量可能会有所不同。

3D查找的信用额转到Kenneth Eaton / gnovice

相关问题