Function 'subsindex' is not defined for values of class 'cell'

3 views (last 30 days)
Cristian Martin
Cristian Martin on 18 May 2022
Commented: Cristian Martin on 18 May 2022
TIP1 = {'ITS A GREAT CAR'};
setappdata(0,'TIP1',TIP1);
TIP2 = {'ITS A USUAL CAR'};
setappdata(0,'TIP2',TIP2);
function popupmenu1_Callback(hObject, eventdata, handles)
TIP1 = getappdata(0,'TIP1');
TIP2 = getappdata(0,'TIP2');
selectedCar = handles.popupmenu1.Value;
switch selectedCar
case 2
owners = TIP1;
case 3
owners = TIP2;
end
str = [];
for k = 1 : length(owners)
str = fprintf('%s\n%s', str, owners{k});
end
handles.edit1.Max = 2;
handles.edit1.String = owners;
function pushbutton2_Callback(hObject, eventdata, handles)
TIP1 = getappdata(0,'TIP1');
intraretext = handles.popupmenu1.String;
TIP1 = [handles.edit1.String(TIP1);intraretext];
setappdata(0,'TIP1',TIP1);
when I push button 1 receive this error
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
Error in testintrod>pushbutton2_Callback (line 97)
TIP1 = [handles.edit1.String(TIP1);intraretext];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in testintrod (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)testintrod('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
what's wrong?Thanks!

Answers (2)

Voss
Voss on 18 May 2022
What's wrong is that TIP1 is a cell array, and you can't use a cell array as an index, as in here you are attempting to access the TIP1 index of handles.edit1.String:
handles.edit1.String(TIP1)
(What the right thing would be is hard to say because I don't know what the intent is.)
  3 Comments

Sign in to comment.


Jan
Jan on 18 May 2022
What is the purpose of
handles.edit1.String(TIP1)
Here TIP1 = {'ITS A GREAT CAR'} is used as index of the variable replied by handles.edit1.String . I cannot guess reliably, what you want to achieve with this code.
Storing values in the ApplicationData of the root object suffers from the same drawbacks as global variables. Avoid this to improve the quality of the code.
  1 Comment
Cristian Martin
Cristian Martin on 18 May 2022
The intention is to modify that TIP1 every time a I push button 1 with another text from text box. So the new value of TIP1 to be modified. Thank you

Sign in to comment.

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by