Problem with sum of numbers in array; first i want just the first number, then 1st and 2nd; then 1st, 2nd and 3rd all the way to the last.

조회 수: 2 (최근 30일)
Hello, Iam trying to make a sum of numbers going from just the first number all the way to the 1st+2nd+3rd+...+last number.
Iam getting error "Index exceeds the number of array elements. Index must not exceed 1." and dont know what Iam doing wrong.3
This is the code I have so far.
x = load('ceny.txt');
x = sort(x);
x_pocet=numel(x);
for i=1:x_pocet
trzba = sum(x(1:x_pocet(i)))
end
"ceny.txt" is just a document with random numbers ranging from 1 to 1000.

채택된 답변

David Hill
David Hill 2021년 12월 18일
  댓글 수: 1
Matyas Lehky
Matyas Lehky 2021년 12월 18일
Not at all what I wanted from the code, but you gave me the correct answer to my question. Back to the drawing board it is. Thank you very much!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by