How can I find the number of row in which the maximum value obtained for a particular column?
2 views (last 30 days)
Show older comments
n = 3
B = rand(n)
A = B
for j = 1:length(A(1,:))
Amax = A(1,j);
for i = 1:length(A(:,1))
if(A(i,j)> Amax)
Amax = A(i,j);
else
Amax = Amax;
end
end
Amax1(1,1)=Amax
end
0 Comments
Accepted Answer
KSSV
on 6 Jan 2021
Read about the function max.
A = rand(10) ; % 10*10 matrix
[val,idx] = max(A(:,3)) % maximum value for the oclumn 3
fprintf('The maximum value occurs in %d row\n',idx)
3 Comments
KSSV
on 6 Jan 2021
A = rand(5,1) ;
maxval = A(1);
idx = 1 ;
for i = 1:length(A)
if A(i) > maxval
maxval = A(i);
idx = i ;
end
end
[maxval idx]
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!