MATLAB Answers

Is there a way to start indexing with 0 in MATLAB?

235 views (last 30 days)
IBM watson
IBM watson on 2 Jan 2019
Edited: Utku Yilmaz on 19 Apr 2020
a=[4 2 5 2]
can I make this happen?
a(0)=4

  0 Comments

Sign in to comment.

More Answers (1)

Bruno Luong
Bruno Luong on 2 Jan 2019
Edited: Bruno Luong on 2 Jan 2019
Yes, but you won't get much support by built-in array stock function
>> M = containers.Map('KeyType','uint32','ValueType','double')
M =
Map with properties:
Count: 0
KeyType: uint32
ValueType: double
>> M(0)=3
M =
Map with properties:
Count: 1
KeyType: uint32
ValueType: double
>> M(0)
ans =
3
>>

  6 Comments

Show 3 older comments
Utku Yilmaz
Utku Yilmaz on 19 Apr 2020
ZeroBased function (link given above) is very useful. 1 based indexing creates problem when I share my code with software developers using C language. The indexes get messy and it becomes very hard to compare codes.
I always used index values starting from 0, as following. But I think, I will utilize ZeroBased function from now on.
for index_A = 0 : 10
for index_B = 0 : 10
value = a_matrix(index_A+1, index_B+1);
end
end

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!