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?

5 vues (au cours des 30 derniers jours)
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 commentaires
Maria
Maria le 9 Mar 2023
Thanks for the comment. However, we have an already working guide...
Rik
Rik le 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 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.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by