フィルターのクリア

Vector Input, GUI edit text box

10 ビュー (過去 30 日間)
Daniel Liberman
Daniel Liberman 2020 年 3 月 13 日
コメント済み: Adam Danz 2020 年 3 月 18 日
Hi,
I am trying to get a vector input from the user in a GUI using edit text boxe, but it seems that the program doesn't recognize the text boxes, although I have them in my GUI. Can someone tell what is the problem?
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Xn=str2num(get(handle.edit1,'string'));
Yn=str2num(get(handle.edit2,'string'));
dn=str2num(get(handle.edit3,'String'));
The class handle has no Constant property or Static method named 'edit1'.
  12 件のコメント
Daniel Liberman
Daniel Liberman 2020 年 3 月 18 日
this*
Daniel Liberman
Daniel Liberman 2020 年 3 月 18 日
No brackets, just commas

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

採用された回答

Adam Danz
Adam Danz 2020 年 3 月 18 日
編集済み: Adam Danz 2020 年 3 月 18 日
The string from a edit box is returned as a cell array of characters. If the expected inputs are a comma separated vector such as "1, 2, 3.14, 5", here's how to exact those values.
s = handles.edit1.String;
d = str2double(strsplit(s{:}, ','));
I suggest using conditional error detection in order to provide the user with feedback in case they use an incompatible format.
s = handles.edit1.String;
try
d = str2double(strsplit(s{:}, ','));
catch
error('Edit field must contain comma separated values such as "6, 5, 3.14"')
end
  2 件のコメント
Daniel Liberman
Daniel Liberman 2020 年 3 月 18 日
Thank you, It works :)
Adam Danz
Adam Danz 2020 年 3 月 18 日
The string value extracted from the edit box is actually a cell array of characters. So, if the user enters "1,1,2,4" the string output will be {'1,1,2,4'}. The {:} part of my answer solves that by returning the character array within the cell array.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by