MATLAB Answers


How to use variables of one function into another functions in GUI?

Asked by BHARAT
on 29 Dec 2012

I am a newbie to GUI. I want to create a GUI in which with the help of data entered by user, I will make some initial calculations. Now, I want to use that calculation for other pushbuttons and popupmenu etc.. Please tell me method to do this. With regards Bharat Garg




1 Answer

Answer by Image Analyst
on 29 Dec 2012
 Accepted answer


Sir links provided by you are valuable. However I couldn't succeed in implementing it. Actually what I want to do is: Take 2 numbers "a" and "b" from user. Then make initial calculations as c=a+b and d=a*b and e= a/b. Now there is one listbox on layout where on clicking a particular option from listbox answer is shown on basis of initial calculations.(ex. options on list are 1) show c 2) show e 3) show d*e)

Please make a small GUI and give me its .m file. Please help me. I am struck here for past 10 days. It will be very helpful.

A forum can only assist you to solve the problem by your own. When you want somebody to create the program for you, hire a programmer.

Therefore I suggest to try it, and post a specific question about the occurring problem. Then you will most likely get help here, to solve the single problems step by step.

You're kidding me - 10 days? Here's a snippet that may help you:

% Ask user for a number.
defaultValue = 45;
titleBar = 'Enter a value';
userPrompt = 'Enter the integer';
caUserInput = inputdlg(userPrompt, titleBar, 1, {num2str(defaultValue)});
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
integerValue = round(str2double(cell2mat(caUserInput)));
% Check for a valid integer.
if isnan(integerValue)
    % They didn't enter a number.  
    % They clicked Cancel, or entered a character, symbols, or something else not allowed.
    integerValue = defaultValue;
    message = sprintf('I said it had to be an integer.\nI will use %d and continue.', integerValue);

Here's another link that may help: MAGIC

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!