2014-04-13 1 views

답변

4
result = bsxfun(@eq, A, max(A,[],2)); 
+1

1 AWESOMENESS! 우리는'bsxfun'을 이런 이유로 사랑하지 않습니다! – Divakar

+1

@Divakar 감사합니다! 단 하나 강선전은 항상 좋은 인상을 일으킨다 :-) –

3

코드

%%// Given matrix 
A= [0.1 0.2 0.5;0.3 0.7 0.4] 

%%// Get the column indices of max values across each row into y1 
[~,y1] = max(A,[],2); 

%%// Create a zero matix of size same as A and set the values corresponding 
%%// to y1 along each row as 1 
A1 = zeros(size(A)); 
A1(sub2ind(size(A1),1:numel(y1),y1'))=1 

출력

A = 

    0.1000 0.2000 0.5000 
    0.3000 0.7000 0.4000 


A1 = 

    0  0  1 
    0  1  0