Main Content

cgsl_0101: Zero-based indexing

ID: Titlecgsl_0101: Zero-based indexing
DescriptionUse zero-based indexing for blocks that require indexing. To set up zero-based indexing, do one of the following:
AFor the Index Vector block parameter Data port order, select Zero-based contiguous.

Set block parameter Index mode to Zero-based for the following blocks:

  • Assignment

  • Selector

  • For Iterator

  • Find Nonzero Elements

NotesThe C language uses zero-based indexing.
RationaleA, BUse zero-based indexing for compatibility with integrated C code.
A, BResults in more efficient C code execution. One-based indexing requires a subtraction operation in generated code.
See Alsohisl_0021: Consistent vector indexing method
Last ChangedR2011b


void ZeroIndex(void)
  Y.Out5 = 3.0 * ZeroIndexArray[IndexSel_Zero];

Not Recommended

void OneIndex(void)
  Y.Out1 = OneIndexArray[IndexSel_One - 1] * 6.3;