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') returnend% --- 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
Best Answer