How to retrieve data from the textboxes of a GUI created with GUIDE.
조회 수: 7 (최근 30일)
이전 댓글 표시
How to retrieve data from the textboxes of a GUI created with GUIDE.
I am having trouble understanding the process of taking entered values from textboxes so that the values may be used in a process, e.g. plotting.
I have created a simple GUI with three textboxes (Tags: edit1, edit2 and edit3)
I want to retrieve the values entered and plot a simple graph. I have read through the Matlab notes and help guides and think that I need to use guidata, handles and set, but I can’t seem to get my head around how these commands interact.
The code below is obviously repeated for each textbox:
function edit1_Callback(hObject, eventdata, handles)
%get value as a string from text box and convert to double
number1 = str2double(get(hObject,'string'));
%check that value is a number and display error if it is not
if isnan(number1) || ~isreal(number1)
errordlg('Try Again','Try again','modal')
return
end
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
I ultimately want to plot a simple graph using something like:
x = [0 1 2]
y = [number1 number2 number3]
plot(x,y)
I obviously have a fundamental lack of knowledge on this subject so I would be very grateful if someone could take the time to give me a layman’s explanation of how this works or maybe point me in the right direction for some reading material.
Cheers
Steve
댓글 수: 0
채택된 답변
Jan
2013년 10월 28일
You can access the content of a textbox in any function that has access to the handles object. For instance if you want to access the content of the textbox tagged edit1 from a function called my_fun it would look something like:
function my_fun( hObject, eventdata, handles )
content_str = get( handles.edit1, 'String' )
Use guidata if you want to change the content of a handle. E.g. if you have a handle variable called my_var and you want to assign it a new value you would do
function my_fun( hObject, eventdata, handles )
handles.my_var = 5;
guidata( hObject, handles ); % if you omit this line, the new value will not be set!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!