arrays - Using percentage function with accumarray -
i have 2 arrays:
otpcororder = [61,62,62,62,62,62,62,62,62,62,62,62,65,65,...] aprefcor = [1,3,1,1,1,1,1,1,1,1,2,3,3,2,...]
for each element in otpcororder there corresponding element in aprefcor. want know percent of number 1 each set of unique otpcororder follows:
otpcororder1 = [61,62,65,...] aprefcor1 = [1,0.72,0,...]
i have this:
[otpcororder1,~,idx] = unique(otpcororder,'stable'); ans = otpcororder1 = [61,62,65,...];
and used work "accumarray" used "mean" or "sum" function such this:
aprefcor1 = accumarray(idx,aprefcor,[],@mean).';
i wondering if there exists way use "prctile" function or other function gives me percent of specific element example "1" in case.
thank much.
this 1 approach:
%// make non-zero values 0 aprefcormask = aprefcor == 1; %// have done [otpcororder1,~,idx] = unique(otpcororder,'stable'); %// find number of each unique values counts = accumarray(idx,1); %// find number of ones each unique value sumval = accumarray(idx,aprefcormask); %// find percentage of ones results perc = sumval./counts
results:
inputs:
otpcororder = [61,62,62,62,62,62,62,62,62,62,62,62,65,65]; aprefcor = [1,3,1,1,1,1,1,1,1,1,2,3,3,2];
output:
perc = 1.0000 0.7273 0
Comments
Post a Comment