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 ビュー (過去 30 日間)
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 件のコメント
Maria
Maria 2023 年 3 月 9 日
Thanks for the comment. However, we have an already working guide...
Rik
Rik 2023 年 3 月 9 日
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.

サインインしてコメントする。

採用された回答

Jan
Jan 2023 年 3 月 9 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by