a dropdown converter in matlab appdesign

How to create a drop down converter in appdesign

댓글 수: 10

Geoff Hayes
Geoff Hayes 2022년 7월 4일
@Anwesha Panda - does your GUI have the input/edit text field so that the user can enter the value of the distance between the points, and is there a text field for the output? Are you using App Designer or programmatically creating your GUI?
PA
PA 2022년 7월 4일
the gui is created programitically
have an input/edit text field so that the user can enter the value of the distance between the points but there is no text field for the output have to create one
Geoff Hayes
Geoff Hayes 2022년 7월 4일
I suspect you want a callback for the drop down so that if that selection changes, then you can update the output text.
PA
PA 2022년 7월 5일
i am not sure that i understand. could you explain a bit more?
If you use App Designer as I suggested below in my answer it will automatically create a callback function and you can put your code in there. If you're doing it the hard way (manually) then you need to create that callback function yourself and tell the ui function you created the drop down list with what the name of the callback function is.
PA
PA 2022년 7월 5일
okay and as i am doing it manually i have created the callbackfunction for the dropdown. Thank you so much:)
PA
PA 2022년 7월 5일
i also want to ask that how can i adapt the string value in uilabel
Image Analyst
Image Analyst 2022년 7월 5일
편집: Image Analyst 2022년 7월 5일
@AP did you look at the documentation for uilabel?
text = sprintf('%s\n%s','Line 1','Line 2');
label = uilabel('Text',text,'Position',[100 100 100 32]);
So to change it you should be able to simply do
label.Text = 'Blah Blah Blah fubar snafu'; % Whatever.
PA
PA 2022년 7월 6일
thanks, i did but i have to adopt the strings on the same space and it get overwritten.
@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일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

PA
2022년 7월 4일

댓글:

2022년 9월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by