The error may be generated because the 'Value' property of the listbox is greater than the length of the cell array that is being assigned to the 'String' property. In other words, if the listbox has a 'Value' of 10, the cell array assigned to the 'String' property must have at least 10 elements.
To further demonstrate why the error might be occurring and to help with fixing the issue, consider the following code, which should run without errors in MATLAB R2015b:
>> MyString={'1','2','3','4','5'};
>> b=uicontrol('Style','listbox','Min',0,'Max',2,'Value',2);
>> set(b,'String',MyString)
However, the following code will generate the error:
>> MyString={'1','2','3','4','5'};
>> b=uicontrol('Style','listbox','Min',0,'Max',2,'Value',10);
>> set(b,'String',MyString)
The difference between the two blocks of code above is that the second block of code has a 'Value' that is greater than the number of elements in the string.
Best Answer