Function 'subsindex' is not defined for values of class 'cell'
2 views (last 30 days)
Show older comments
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!
0 Comments
Answers (2)
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
Voss
on 18 May 2022
This will prepend edit1's String to the beginning of TIP1 and store the result as TIP1, assuming both are cell arrays or string arrays:
TIP1 = [handles.edit1.String(:); TIP1(:)];
Maybe that's similar to what you're trying to do, and you can modify it as necessary.
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.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!