Changing lower bound of an array

조회 수: 1 (최근 30일)
Huugin
Huugin 2013년 5월 24일
Hi
Can I change the lower bound of an array. E.g can I have an array with starting index 0?
Atm
ex(0)=2
Will not work
Thanks for any suggestions!, and have a nice weekend :-)

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 24일
Example: y(n)=n^2+1 and you want to start from 0
for n=0:10
y(n+1)=n^2+1
end
% y(1) correspond to index 0
  댓글 수: 1
Azzi Abdelmalek
Azzi Abdelmalek 2013년 5월 24일
편집: Azzi Abdelmalek 2013년 5월 24일
You can also use
y=@(n) n.^2+1
y(0:10)

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


Daniel Shub
Daniel Shub 2013년 5월 24일
I believe with a huge amount of work overloading some of the key functions (e.g., subsref and subsasgn) you can probably achieve a pretty seamless re-indexing interface. That said, even if it was easy, DO NOT DO IT. MATLAB uses 1-based indexing. Get used to it.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by