How can I use created edit texts that were created by a pushbutton and (currently) have the same name?

3 views (last 30 days)
Hello!
I am currently making a GUI in guide. I created a pushbutton in guide. This button creates two edit texts (load;speed) that are created via code inside the GUI in the callback function of the pushbutton. The present code works fine (creates new and newer bias points), but i dont know how to reference them in my code (how to get their values) since i dont know their 'Tag'-s. I can use the first load and speed values, since i created them in guide, so i get them by their tag properties. Also, in my version, all of the button-created load and speed edit boxes have the same name (textload, textspeed).
Anyway, here's that part of my code, I hope you can help me:
in the opening function:
handles.basepos1 = [567 380 187 55]; handles.basepos2 = [874 380 187 55]; set(handles.newpoint, 'UserData', 0);
in the pushbutton's callback function:
counter = get(hObject, 'UserData') + 1; set(hObject, 'UserData', counter); delta= [0 -80 0 0]; basepos_1 = handles.basepos1 + counter * delta; basepos_2 = handles.basepos2 + counter * delta; textload = uicontrol(handles.p1, 'Style', 'edit', 'String', 'Load (N)', 'Position', basepos_1); textspeed = uicontrol(handles.p1, 'Style', 'edit', 'String', 'Speed (m/s)', 'Position', basepos_2);

Accepted Answer

OCDER
OCDER on 27 Jul 2018
Your "tag" is pretty much the variable name you store the uicontrol handle to.
handles.textload = uicontrol(handles.p1, 'Style', 'edit', 'String', 'Load (N)', 'Position', basepos_1);
handles.textspeed = uicontrol(handles.p1, 'Style', 'edit', 'String', 'Speed (m/s)', 'Position', basepos_2);
guidata(hObject, handles)
%Now you can get the handles of the textload and textspeed
set(handles.textload, 'string', 'loading');

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!