ntough
ntough

Reputation: 363

Cell contents indices must be greater than 0 error in matlab

This is a simple snippet to create an cell array and initialize it. I got the following error and it confuses me. Many thanks for your time and attention.

>> o={};
>> a=1:9; b=0;

>> o{end}={a}
Cell contents indices must be greater than 0

>> o{end}=a;
Cell contents indices must be greater than 0

Upvotes: 0

Views: 2803

Answers (1)

srthompers
srthompers

Reputation: 169

Your issue is very simple: o contains nothing, so the end enumerator will return element number 0, which isn't a valid index. What you want is either o{end+1}=a, or more simply, o{1}=a.

Upvotes: 3

Related Questions