How to automatically update the value in a string in an edit box with a value in another edit box but still allow the user to overwrite this value?

7 views (last 30 days)
I have a gui guide where I ask the user if it knows a value (number) in an edit box.
If the user knows this value I want the value in another edit box to automatically update. However, I want the user to be able to update/overwrite the value in the second edit box.
Any help is welcome. Thanks in advance.
  3 Comments
Rik
Rik on 9 Mar 2023
Then it should be easy to generate the code and clean up the mess that GUIDE made, after which you no longer rely on a fragile system with two separate files, one of which easily breaks when edited in a wrong version of Matlab.
But the second part of my comment should still be worth a try regardless.

Sign in to comment.

Accepted Answer

Jan
Jan on 9 Mar 2023
Without GUIDE but a working demonstration:
handles.FigH = figure;
handles.Edit1 = uicontrol('Style', 'Edit', ...
'Units', 'Normalized', ...
'Position', [0.1, 0.55, 0.8, 0.4], ...
'Callback', @Edit1CB);
handles.Edit2 = uicontrol('Style', 'Edit', ...
'Units', 'Normalized', ...
'Position', [0.1, 0.05, 0.8, 0.4]);
guidata(handles.FigH, handles);
function Edit1CB(Edit1, EventData)
handles = guidata(Edit1);
set(handles.Edit2, 'String', get(Edit1, 'String'));
end
The callback of the first edit field copies its contents to the second one, but you can still edit the second one manually.
In your GUIDE code you omit the explicit guidata() calls. Insert the corresponding Callback to the first edit field.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!