以根据分位数标记元素位置为例,假如某一元素小于10%分位标记为1,小于20%分位而大于10%分位则标记为2……,以此类推
传统方法:
label = zeros(length(data),1);
for j = 1:length(label)
disp(num2str(j))
if data(j) > prctile(data,90)
label(j) = 1;
continue
elseif data(j) > prctile(data,80) && data(j) < prctile(data,90)
label(j) = 2;
continue
elseif data(j) > prctile(data,70) && data(j) < prctile(data,80)
label(j) = 3;
continue
elseif data(j) > prctile(data,60) && data(j) < prctile(data,70)
label(j) = 4;
continue
elseif data(j) > prctile(data,50) && data(j) < prctile(data,60)
label(j) = 5;
continue
elseif data(j) > prctile(data,40) && data(j) < prctile(data,50)
label(j) = 6;
continue
elseif data(j) > prctile(data,30) && data(j) < prctile(data,40)
label(j) = 7;
continue
elseif data(j) > prctile(data,20) && data(j) < prctile(data,30)
label(j) = 8;
continue
elseif data(j) > prctile(data,10) && data(j) < prctile(data,20)
label(j) = 9;
continue
elseif data(j) < prctile(data,10)
label(j) = 10;
continue
end
end
快速方法:
label = zeros(length(data),1);
label(data > prctile(data,90)) = 1;
label(logical((data > prctile(data,80)).*(data < prctile(data,90)))) = 2;
label(logical((data > prctile(data,70)).*(data < prctile(data,80)))) = 3;
label(logical((data > prctile(data,60)).*(data < prctile(data,70)))) = 4;
label(logical((data > prctile(data,50)).*(data < prctile(data,60)))) = 5;
label(logical((data > prctile(data,40)).*(data < prctile(data,50)))) = 6;
label(logical((data > prctile(data,30)).*(data < prctile(data,40)))) = 7;
label(logical((data > prctile(data,20)).*(data < prctile(data,30)))) = 8;
label(logical((data > prctile(data,10)).*(data < prctile(data,20)))) = 9;
label(logical(data < prctile(data,10))) = 10;