f



Passing Value from one function to another function in MATLAB GUI!

Hi,

Here is the screenshot of my GUI:

http://i54.tinypic.com/iemg7o.png

In the pushbutton1 of File Path which has Browse written over it, I have used the following code:

function pushbutton1_Callback(hObject, eventdata, handles)
[FILENAME, PATHNAME] = uigetfile;

And in the pushbutton2 which has Send! written over it, I have used the following code:

function pushbutton2_Callback(hObject, eventdata, handles)
input_sec_info=get(handles.edit1,'String');
Encoder(input_sec_info,FILENAME, PATHNAME);

Now that the pushbutton2 passes input_sec_info,FILENAME, PATHNAME as arguments to Encoder function. But the FILENAME, PATHNAME are deleted as they are a part of another function.

So, when I click the pushbutton1, the variables FILENAME, PATHNAME are created and saved. But when I click the pushbutton2, the variables FILENAME, PATHNAME are deleted because they are part of someother function. But I need all 3 variables including input_sec_info,FILENAME, PATHNAME.

So, is there anyway that I can save variables FILENAME, PATHNAME and use them later. I know how to save it in .mat and recall it but it makes the GUI very un-friendly (because it opens up other dialog boxes for saving .mat file even if you give it the .mat file name to be saved with). Is it possible to do it through the code?

Thank you.
0
6/22/2011 8:57:02 AM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
995 Views

Similar Articles

[PageSpeed] 30

"Asad Asad" wrote in message <itsaou$1sh$1@newscl01ah.mathworks.com>...
> Hi,
> 
> Here is the screenshot of my GUI:
> 
> http://i54.tinypic.com/iemg7o.png
> 
> In the pushbutton1 of File Path which has Browse written over it, I have used the following code:
> 
> function pushbutton1_Callback(hObject, eventdata, handles)
> [FILENAME, PATHNAME] = uigetfile;
> 
> And in the pushbutton2 which has Send! written over it, I have used the following code:
> 
> function pushbutton2_Callback(hObject, eventdata, handles)
> input_sec_info=get(handles.edit1,'String');
> Encoder(input_sec_info,FILENAME, PATHNAME);
> 
> Now that the pushbutton2 passes input_sec_info,FILENAME, PATHNAME as arguments to Encoder function. But the FILENAME, PATHNAME are deleted as they are a part of another function.
> 
> So, when I click the pushbutton1, the variables FILENAME, PATHNAME are created and saved. But when I click the pushbutton2, the variables FILENAME, PATHNAME are deleted because they are part of someother function. But I need all 3 variables including input_sec_info,FILENAME, PATHNAME.
> 
> So, is there anyway that I can save variables FILENAME, PATHNAME and use them later. I know how to save it in .mat and recall it but it makes the GUI very un-friendly (because it opens up other dialog boxes for saving .mat file even if you give it the .mat file name to be saved with). Is it possible to do it through the code?
> 
> Thank you.

Hi,
 under pushbutton1callback,
handles.Filename=FILENAME;
handles.Pathname=PATHNAME;
Since 'handles' is accessible across the GUI code, you can access FILENAME & PATHNAME from handles struct in the pushbutton 2 callback.

The other way to do this could be making the two variables global.
HTH,
Krishna.
0
6/22/2011 9:45:20 AM

"Asad Asad" <muhammad.asad@gmail.com> wrote in message 
news:itsaou$1sh$1@newscl01ah.mathworks.com...
> Hi,
>
> Here is the screenshot of my GUI:
>
> http://i54.tinypic.com/iemg7o.png

*snip*

> So, is there anyway that I can save variables FILENAME, PATHNAME and use 
> them later. I know how to save it in .mat and recall it but it makes the 
> GUI very un-friendly (because it opens up other dialog boxes for saving 
> .mat file even if you give it the .mat file name to be saved with). Is it 
> possible to do it through the code?

If you're using GUIDE:

http://www.mathworks.com/help/techdoc/creating_guis/f5-998197.html

If not:

http://www.mathworks.com/help/techdoc/creating_guis/f13-998197.html

-- 
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 

0
slord (13689)
6/22/2011 1:32:45 PM
Reply:

Similar Artilces:

How to pass value from one Button Group function to another function
Currently i have created two radio buttons in my GUI. I using the Button Group (SelectionChangeFcn) to control my radio button. If radio button 1 has been selected, it will pass a value "hello world 1" to another function. If radio button 2 has been selected, it will pass a value "hello world 2" to another function. Is't by using SET and GET? Can some one guide me the coding? function hand_SelectionChangeFcn(hObject, eventdata, handles) switch get(eventdata.NewValue,'Tag') % Get Tag of selected object. case 'left' % i need to pass 'hel...

Passing a MATLAB function to a C function
Hi. I have the following setup: 1) a function of several variables implemented in MATLAB which I want to optimize, i.e. to find variable values for which the function gives minimal value, 2) a very good local optimization procedure implemented in C which I want to use repeatedly to optimize the above mentioned function, and 3) a procedure for generating the local search starting points implemented in MATLAB again. Thus, I need to run a MATLAB function which will iteratively generate a starting point and run a C-function local search procedure from that point. I must pass a function de...

call to matlab function from matlab GUI stalls
I have the following problem. I have created a simple Matlab GUI (for our purposes it can just be considered a Matlab function) which gathers some parameters and then invokes a perl script that in turn calls other perl and Matlab scripts to perform various calculations. If instead of using the Matlab GUI, I run the perl command from the unix prompt, the flow runs and concludes correctly. BUT if I invoke the flow from the Matlab GUI (function), then it runs correctly by calling various other perl and Matlab scripts, but then when it reaches the third Matlab function call, it consistently stalls...

MATLAB function name passed in a function call
I have a statement as follows: wc = FWT_PO(x_use,4,QMF) where QMF is the name of a MATLAB function (QMF.m, the Quadrature Mirror Filter function). x_use is an array. The function FWT_PO is just regular MATLAB statements. Problem is that control immediately goes to QMF.m whereupon it bombs out with a "not enough input arguments" error message. Do not understand this form of function call line, cannot find it described in the MATLAB "Help", & thus do not understand cause of the error or how to fix. In article <eed8cdf.-1@webx.raydaftYaTP>, kbannister@ara.com says...

passing arguments from one function to another function
Hi, I am trying to develop a GUI in Matlab and found a problem when trying to pass arguments to a function, that is, those arguments are returned from a different function. My idea was to save the returned arguments in the handles structure, and next to pass the handles structure fields to the function. I get an error when I try to access to the fields where it is supposed I saved the returned arguments. The error is that I am referencing a o non-existent field. For I better understanding I send you my code: 1.- Code of my application: function varargout = Balance_Enlace_GUI(varargin) % BA...

Passing a ParamArray from one Function to another Function
Greetings: I have two functions and I would like to pass the ParamArray gathered from one function to the other function. For the purposes of this post, let's say that they are calculating averages (they're actually processing a sequence of pairs of variants and the sequence is of unknown length). I want something like these two functions: #1 Function AverageSequenceOfNumbers(ParamArray SequenceOfNumbers As Variant) as Double .... End Function #2 Function AverageSequenceOfNumbersPlusOne(ParamArray SequenceOfNumbers as Variant) as Double AverageSequenceOfNumbersPlusOne = AverageSeq...

how to call one function from another function in gui guide
i am working on a GUI Guide. i have made to buttons 1. upload image 2. process image the first button is working properly. but the second one can not read the image uploaded by the first one!. i dont want to use global either. what to do???? i was not able to use setappdata n getappdata! please guide me on this too here is my code: % --- Executes on button press in upload. [filename, pathname, filterindex] = uigetfile( ... { '*.jpg','JPEG (*.jpg)'; ... '*.bmp','Windows Bitmap (*.bmp)'; ... '*.fig','Figures (*.fig)'; ....

Passing function arguments to Matlab via Matlab Engine
If someone can help me here , it will be greatly appreciated ... I was able to set up the Matlab Engine Call via C properly without any issues.. , done it via a C function calll .. something like this ... : ////////////////////////////////////////////////// #include <math.h> ..... int matlab_call(double Amp) { Engine *ep; mxArray *A = NULL, *result = NULL; if (!(ep = engOpen(""))) { fprintf(stderr, "\nCan't start MATLAB engine\n"); return EXIT_FAILURE; } ... } ////////////////////////////////////////////////// Now i want to...

How to pass a function to a function?, and how to pass the variables of the function?
I'd like to write a function like: function f(){ ... bla ...} f_example(f); function f_example($function_to_execute) {...bla... $function_to_execute() ...bla....} AND how to pass the variable of the function : function f_example($function_to_execute($var1,$var2)) {...bla... $function_to_execute() ...bla....} Thank you in advance for the time you'll spend for me, Andrea. I'm sorry, I don't quite understand what you are asking... If you are asking how to use results of a function in another function then you should do this. function test1() { return "Hello Wor...

passing value from one function to another
i'm having some trouble. by using GUIDE i did created a 'edit text' bar and a 'push button'. User insert some data in the 'edit text' bar and continue by clicking the 'push button'. Once the 'push button' has been pressed, a popup message box (msgbox) will display the 'edit text''s value. Can some one guide me? % This is the 'edit text' bar % Get value from first name function fname_Callback(hObject, eventdata, handles) first=get(hObject,'String'); % This is the 'push button' function push_Callback(hObject, event...

Call Matlab functions from mex (matlab function's input is string)
Here is my mex code: void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ char errBuff[1]={'A'}; //create mxArray pointer mxArray *mxerr; //copy errBuff to mxArray mxerr = mxCreateString(errBuff); //initialize mxArray with errBuff char array, return to pointer //call matlab function mexCallMATLAB(0,NULL, 1,mxerr, "errorCatcher"); //destroy mxArray mxDestroyArray(mxerr); //destroy mxArray printf("destroyed mex array\n"); }//end of mexFunction errorCatcher accepts string inp...

Trying to pass values of variables from a redefined function into another function
Here's the problem: I have a function that references another one in this manner: class circleType: public pointType so, pointType is redefined by circleType, thereby giving circleType access to all the functions in pointType if need-be. Here is the function I am using in pointType: void pointType::setCoords(double xCoord, double yCoord) { pointX = xCoord; pointY = yCoord; } it is being accessed in circleType in this manner: void circleType::getCoords(double xCoord, double yCoord) { //set the external point using the pointType header pointType::setCoords(pointX, pointY); co...

From Matlab GUI call another individual function
Hi,=20 Now I am doing a small project using Matlab GUI, I met a general problem ab= out fuction call and transmission of variables between callback function wo= rkspace and the base workspace. Ok, let me simply describe the case and my expect: 1.GUI with its m code, inside each button callback functions, here are some= computational functions defined 2.From that sorts of function, it generate a single .mat file which will be= output to the current working directory 3.On the main frame, I would like to use another button, to call a single f= unction .m file named "funct...

passing data from one matlab gui to another
Hi there, I am trying to write two matlab gui's and pass data between them. I have been having problems returning output from a matlab gui on to matlab interface/workspace. If someone knows abt it, please could you respond. Thanks, Harish Harish wrote: > > > Hi there, > > I am trying to write two matlab gui's and pass data between them. I > have been having problems returning output from a matlab gui on to > matlab interface/workspace. If someone knows abt it, please could > you > respond. > > Thanks, > Harish Use the function GUIDATA to store an...

passing a value of a variable from one function to another
hi guys, Supposidly i have a function code:-------------------------------------------------------------------------------- decode_ip(u_char *packet, u_char flags) -------------------------------------------------------------------------------- that has a variable which is code:-------------------------------------------------------------------------------- char destination_ip[40]; //Here we save destination IP -------------------------------------------------------------------------------- where we save a specific value code:----------------------------------------------------------...

Please Help on passing data from one function to another function [Urgent]
If I make two interfaces and generate two *.m files via GUI, how can I get the value from one function and use it in another function? If both of the files created via GUI and I don't want the parameter to be a global variable, so what should I do? LittleGirl wrote: > > > If I make two interfaces and generate two *.m files via GUI, how > can > I get the value from one function and use it in another function? > > If both of the files created via GUI and I don't want the parameter > to be a global variable, so what should I do? Call another GUI files with input...

passing function into another function
Hi, I couldn't work out the syntax for the following: class Reports def self.This; end def self.That; end end def do_something_with_a_report report # calls Reports::This or Reports::That, dtermined by what report is # something like report.call ? end I want to do something like: do_something_with_a_report Reports::This But that calls Reports::This and sends that value to the do_something_with_a_report function. In other words, I want to do something like passing a function pointer to a function in C. On Tue, 12 Sep 2006, Joe Van Dyk wrote: > Hi, > > I couldn...

Calling a callback function from another callback in the same Matlab GUI
Hello, this is my first post here although I have found these pages hugely helpful over the last few years :) Some background: I have a GUI which allows the user to select one of 6 parameters (from the drop down menu) to plot, and one of several data files to use to compute values for the chosen parameter. I need the callback which chooses the data file to be able to call the callback of the parameter selector, as that callback chooses the part of the data file that we need to use for the selected parameter. If I simply call SelectParam_Callback(h.SelectParam, [], h); inside th...

Passing &rest values from one function to another
I'd like to have the &rest parameter list for one function become the &rest list for another, as in: (defun rest-1 (&rest xs) (rest-2 xs)) (defun rest-2 (&rest ys) ys) (rest-1 1 2 3) ;;If all went according to plan, this would return '(1 2 3), not '((1 2 3)) Is there a Lisp idiom for doing this? I thought of writing a macro elements-of that would function as follows: (elements-of '(1 2 3)) => (nth 0 '(1 2 3)) (nth 1 '(1 2 3)) (nth 2 '(1 2 3)) But I don't know if it's possible to return multiple forms from a macro like this. I c...

MATLAB GUI design
Hi all: I'm writing a GUI programatically to leverage some m-files people have wrote on the File Exchange. I have a lot of uicontrols to deal with and I'd like to separate the constructors from the main file, which will contain the callbacks. So the function I call will be, say, CreateUIControls(), and I know that feeding into it I need the handle for the parent object. But when I return to the parent (the function actually creating the GUI), what do I return? And what commands are necessary before I return (such as guidata(), etc)? Sorry for the noob questions. I'm pre...

Matlab GUI- passing string and data information to other functions.
I am creating a Matlab GUI. I am currently stuck on how to transfer a string or and data to another function. I've created two pop-up menus that allows the user to scroll down for a particular choice. once the two choice are made, I want those choice to be transfered to another function that plots one choice versus the other- the graph will vary based on the choice. My problem is get the information of the choice to transfer to the function that graphs the info. ...

diff() function giving one less value in Matrix Matlab
I'm using a position vector and its derivative using diff() in Matlab, the position vector P and and its derivative Pd = diff(P) but its giving one less value as per derivative's rule of taking difference. But How can I avoid this? Ahsham Ali <hafiz.m.ahsan.ali@gmail.com> wrote in message <419c1d82-e6a7-4bf8-a0f0-0f545088ba9d@googlegroups.com>... > I'm using a position vector and its derivative using diff() in Matlab, the position vector P and and its derivative Pd = diff(P) but its giving one less value as per derivative's rule of taking difference. But How c...

pass function into another function as parameter?
hi, is it possible to pass a function into another function as a parameter? Say i have these: function SaveMe(text) {...} function SaveMeNow(text) {...} function WhichToSave(x, y, z) {...} a button will call WhichToSave, that function will perform some logic and then call one of the Save methods, can i pass that method in as say parameter z and have it just call the function right away, passing one of the SaveMe methods a parameter which is determined by the WhichToSave method? Thanks. On Nov 20, 3:57=A0pm, soni2926 <soni2...@yahoo.com> wrote: > hi, > is it possible to pass ...

how to pass a function as an argument to another function
Hi, I want to pass my function myFunc('a', 'b', 'c') as an argument to another function. However, this will not work doStuff('x', 'y', myFunc('a', 'b', 'c')) because the expression "myFunc('a', 'b', 'c')" gets evalauted before it is passed to the function "doStuff". Does this make sense? Thanks for any help , - Dave laredotornado@zipmail.com said: > >Hi, > >I want to pass my function > >myFunc('a', 'b', 'c') > >as an argument to a...

Web resources about - Passing Value from one function to another function in MATLAB GUI! - comp.soft-sys.matlab

Wave function - Wikipedia, the free encyclopedia
... (a ball attached to a spring ) in classical mechanics (A-B) and quantum mechanics (C-H). In quantum mechanics (C-H), the ball has a wave function ...

Eating chocolate 'improves brain function' - study
... news for those with a sweet tooth - a recent study has found that regular chocolate consumption is associated with better cognitive function. ...

Resource sector may outsource finance functions to Asia
Outsourcing financial functions to Asia is one tactic struggling Australian energy and resources companies may use this year to survive the slump ...

Using Functions to Make Better Abstractions
... (code that is tightly coupled to its own implementation details). I was wrong. I was wrong because I had an incomplete understanding of functions. ...

Cisco launches new network functions virtualization infrastructure solution to help service providers ...
Al-Bawaba Cisco launches new network functions virtualization infrastructure solution to help service providers run network ... Al-Bawaba ...

A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003
**[A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003](http://www.j-bradford-delong.net/movable_type/2 ...

Yahoo Begins Grim Job of Closing Functions, Laying Off Staff
Yahoo Food is closing, and other digital magazines on tech, travel and beauty are also scheduled for closing or major cutbacks.

Don’t tase me, bro: Study shows being shocked by a Taser disrupts brain function
Researchers at Drexel shot a bunch of college students with 50,000 volts. The result? Short-term declines in cognitive function comparable with ...

Engineers 3D Print Tissue That Mimics How The Human Liver Functions
Engineers say they have 3D printed life-like liver tissue that could be a new platform in the lab to test the efficacy of drugs saving pharmaceutical ...

A 3D Printed Jet Engine Appears to Function
... jet engine . You may remember seeing a 3D printed jet engine grace our front page back in October. That one was beautiful didn’t function . ...

Resources last updated: 2/28/2016 2:19:41 PM