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

2 ビュー (過去 30 日間)
Cristian Martin
Cristian Martin 2022 年 5 月 18 日
コメント済み: Cristian Martin 2022 年 5 月 18 日
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!

回答 (2 件)

Voss
Voss 2022 年 5 月 18 日
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 件のコメント
Voss
Voss 2022 年 5 月 18 日
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.
Cristian Martin
Cristian Martin 2022 年 5 月 18 日
Thanks!

サインインしてコメントする。


Jan
Jan 2022 年 5 月 18 日
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 件のコメント
Cristian Martin
Cristian Martin 2022 年 5 月 18 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by