a dropdown converter in matlab appdesign

1 回表示 (過去 30 日間)
PA
PA 2022 年 7 月 4 日
コメント済み: Image Analyst 2022 年 9 月 1 日
How to create a drop down converter in appdesign
  10 件のコメント
PA
PA 2022 年 7 月 6 日
thanks, i did but i have to adopt the strings on the same space and it get overwritten.
Image Analyst
Image Analyst 2022 年 9 月 1 日
@AP - not sure what that means. What does it mean to "adopt" the strings? How does it get overwritten? Are you just reassigning the string to some static text label? Or do you have some other control on your figure that is covering up your string label?

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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 7 月 4 日
Why not use App Designer? Why are you creating yoru GUI the hard way by creating some or all of your components programmatically in code?
Here's a snippet asking the user for two inputs (numbers) that you may want to adapt, like don't convert the second one to a number and leave it as a string.
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter values';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by