-3

I'm trying to make a for-loop in matlab that would return the following:

C_1 = 0
C_2 = 0
C_3 = 0
C_4 = 0
C_5 = 0

But, before that, I want also a value as follows: C_0 = 0.

I gave it a try as follows but didn't work:

function test
    C{0} = 0;
    for i=1:5
        C{i} = 0
    end
end

How can I solve this issue?

Thanks.

Shai
  • 111,146
  • 38
  • 238
  • 371
Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • 2
    possible duplicate of [Is zero based indexing available in MATLAB](http://stackoverflow.com/questions/4239907/is-zero-based-indexing-available-in-matlab) – Oliver Charlesworth Feb 12 '13 at 09:34
  • Just an observation: though you cannot use `C{0}`, you can in fact use `for i=0:5` so would not need to separate the two cases. – Dennis Jaheruddin Feb 12 '13 at 09:41
  • please delete this question as you have already duplicated it into a newer version. – Shai Feb 12 '13 at 12:00

1 Answers1

0

The simple answer: You can't use C{0}

The simple workaround:

Increase all indices by 1, use C{1} to C{6} instead of C{0} to C{5}

For the complex answer, look at the link given by @Oli

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122