Sunday, 15 March 2015

matlab - Comparing columns of matrix and giving boolean output -



matlab - Comparing columns of matrix and giving boolean output -

i have checked other questions. didn't find answer. have matrix of n * 2 size. want compare 1st , 2nd column , based on greater want assign 0/1 respective index. suppose want output

a = 1 2 4 3 7 8

i want output this

out = 0 1 1 0 0 1

i did :

o1 = a(:,1) > (:,2) o2 = not(o1) out = [o1, o2]

this job sure there's improve way this. need suggestions on that/. forgot mention, datatype float in matrix.

a more generic solution can handle matrices more 2 columns:

out = bsxfun(@eq, a, max(a,[],2));

matlab

No comments:

Post a Comment