indexing of starting element of sum

조회 수: 1 (최근 30일)
asad jaffar
asad jaffar 2019년 4월 3일
댓글: Jan 2019년 4월 5일
function [summa,index=nba_aj(b,n)
s=length(b);
i=0;
if n>s
a=0
k=-1
elseif n<=s
q=movsum(b,n)
summa=max(q)
what should i do after this for index finding
% here i want to know the index
can you guys help me the required answer is
summa=13,index=4 b=[1 2 3 4 5 4 3 2 1] n=3
summa=5,index-5 b=[1 2 3 4 5 4 3 2 1] n=1
  댓글 수: 3
asad Jaffar
asad Jaffar 2019년 4월 4일
Yeah but no answer yet , please take a look at this No ,its not about the index of maximum number in an array,its about starting index of maximum sum for example ([1 2 3 4 5 4 3 2 1]9) this is the example of above question mentioned and the answer is summa=25 ,index= 1. The algorithm is that a=movsum(v,n) Summa=max(a) Now if i found index of max it will give 5,but it should be 1 because it starts with 1 in an array. Another example ([1 2 3 4 5 4 3 2 1],3) Summa=13,index = 4 Now max is 5 in array but index in answer is 4 its about starting of number of sums 4+5+4=13 index of 4 in sum is 4 , kindly help me with this index thing ,give hint.
Jan
Jan 2019년 4월 5일
As Walter has said already: This topic has been discussed already and you find a working solution there also. All you need is reading the documentation of movsum:
doc movsum
and to learn, why you have to ignore the marginal elements by setting 'EndPoints' to 'discard'. In addition you have to use the 2nd output of max.
Pleae note that posting working solution of homework questions is not really useful.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by