how to enter a vector in edit text, GUI

조회 수: 4 (최근 30일)
Dominika
Dominika 2014년 7월 7일
댓글: Robert Cumming 2014년 7월 8일
Hi,
I want to enter a vector 1x18 into edit text in GUI, e.g:
0.03 0.02 0.01 0.02 0.01 0.01 0.02 0.01 0.04 0.03 0.02 0.01 0.01 0.02 0.02 0.01 0.01 0.1
So far I used to enter only single value. My current callback:
function edit40_Callback(hObject, eventdata, handles)
% hObject handle to edit40 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit40 as text
% str2double(get(hObject,'String')) returns contents of edit40 as a double
InString = get(hObject, 'String');
InString = strrep(InString, ',', '.');
eta_tot=str2double(InString);
set(handles.edit40, 'String', InString);
if isnan(eta_tot)
errordlg('You must enter a numeric value','Invalid Input','modal')
uicontrol(hObject)
return
else
end
if (eta_tot<0 | eta_tot>1)
errordlg('Value should range from 0 to 1','Invalid Input','modal')
uicontrol(hObject)
end
Thanks for any ideas,
Dominika

답변 (2개)

Robert Cumming
Robert Cumming 2014년 7월 7일
A few places to look:
help strread
help str2num
help textscan
There are many ways to do what your looking for.

Dominika
Dominika 2014년 7월 8일
편집: Dominika 2014년 7월 8일
Thank you for your suggestions. I try with str2double:
function edit40_Callback(hObject, eventdata, handles)
% hObject handle to edit40 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit40 as text
% str2double(get(hObject,'String')) returns contents of edit40 as a double
InString = get(hObject, 'String');
display(InString)
eta_tot=str2double('InString');
celldisp(eta_tot)
I get an error while trying to display eta_tot:
InString =
'0.1 0.1'
Error using celldisp (line 15)
Must be a cell array.
Error in PROGRAM>edit40_Callback (line 1546)
celldisp(eta_tot)
  댓글 수: 1
Robert Cumming
Robert Cumming 2014년 7월 8일
debug your code to find out whats going wrong - you will learn more doing that that me highlighting the errors.
Try simple examples at the matlab commandline to understand how functions work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by