maximum number and indexing

how can i find maximun number from an array for example .a=[2,44,6,77,3,9],how can i find max 2 numbers which are ,44 and 77 from a single command ? and how to know there index .thanks

Answers (1)

maxk(a,2)

7 Comments

the version i am using maxk does not work on it ,and i also dont want to creat a function as i want to use it inside a function ,is there any other way i can find max
[Values,Indices] = sort(a,'descend')
[Values(1:2);Indices(1:2)]
thanks , i also want to know that how can i know the index in a vector
[1 2 3 4 5 4 3 2 1]
sum=4 5 4 =13
index =4
sum=9
index=4
sum=5
index=5
its about sum by movsum(a,n) n=3
a=above vactor
I have answered the question you originally asked.
yeah i know ,i already did that but i am having problem in finding the index
function [a,k]=nba_aj(b,n) ( %b=[1 2 3 4 5 4 3 2 1] n=3,k=index whch should b 4 )
s=length(b);
i=0;
if n>s
a=0
k=-1
elseif n<=s
q=movsum(b,n)
b=max(q)
% here i want to know the index
@asad: If madhan's answer solves your problem, be so kind to accept it.

Sign in to comment.

Asked:

on 3 Apr 2019

Commented:

Jan
on 5 Apr 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!