To get a sense of what I am trying to do:
A = [1, 15200, 3, 5, 7; 15200, 15200, 15200, 7,0; 1,1,1,1, 15200; 9200, 1, 1,1,1]; [val] = max(A, [], 2); indices = find(A==val); [row, col] = ind2sub(size(A), indices); sub = [row, col];
Here's another way, with no loops
% Example data matrix % I modified this a little from your example to have % multiple occurences of row maximum in the 5th row also, to give better % illustration A = [1, 15200, 3, 5, 7; 15200, 15200, 15200, 7,0; 1,1,1,1, 15200; 9200, 1, 9200,1,1]; % get array dimension for later use numRows = size(A,1); % Find the row maximums rowMax = max(A,[],2); % Mark locations where row maximums occur isRowMax = A == rowMax; % Make matrix with random values wherever row maximums occur and zero % everywhere else S = isRowMax.*rand(size(A)); % Select random column amongst occurrences of row maximums % (column where largest element in S occurs is random) [~,selectedColumn] = max(S,[],2); % Return row and column indices for location of maximum in each row sub = [(1:numRows)' selectedColumn]
sub = 4×2 1 2 2 2 3 5 4 1
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.