Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Passing arguments between functions in Matlab

Status
Not open for further replies.

AliShariq

Newbie level 3
Joined
May 8, 2007
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Islamabad, PK
Activity points
1,299
Hi, I'm new to Matlab and this Forum as well. Let me know if any one could help me out in passing arguments from one function to another in matlab or using some sort of global variables.

Any sort of help will be appreciated..

Regards,
Ali
 

meto

Junior Member level 1
Joined
Apr 9, 2006
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,399
Re: Matlab help

For exp. let say your function name "help" then

[xout,yout]=help(ar1,ar2,ar3)

ar1,ar2 and ar3 your input argumants and also xout and yout are your return values.you can call this function like this

>>[xout,yout]=help(1,2,3)

then command returns outputs values
 

echo47

Advanced Member level 5
Joined
Apr 7, 2002
Messages
3,942
Helped
638
Reputation
1,274
Reaction score
89
Trophy points
1,328
Location
USA
Activity points
33,176
Matlab help

Yes.
For more info and examples, search your MATLAB built-in help for "function" (declare M-file function).
Also search for "global" (declare global variables).
 

armin

Newbie level 6
Joined
May 18, 2007
Messages
14
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,281
Activity points
1,383
Matlab help

hi Ali

passing arguments from function F1 to F2 in MATLAB:
assume that you want to pass variable V1 from F1 to F2

you can declare V1 as a global variable at all places that you use V1:
%-------------------
function ..=F1(...)
..
global V1
V1=5;
...
end
%------------------
and use it in F2:
%-------------------
function ...=F2(..)
....
global V1
V2=V1+3;
...
end
%-----------------------

also you can include V1 as output of F1 & call F1 whenever you need to use V1.


hope it helped.
Armin
 

mondunno

Advanced Member level 4
Joined
Jan 11, 2007
Messages
119
Helped
15
Reputation
30
Reaction score
4
Trophy points
1,298
Activity points
1,907
Matlab help

just try the matlab online help yourself.

i've done the same

all the best


do you mean callin another function from one? if you're using older version(<6) matlab...function within a function is an error
 

mar_deepmode

Member level 1
Joined
May 3, 2007
Messages
36
Helped
15
Reputation
30
Reaction score
8
Trophy points
1,288
Location
Lisboa-Portugal
Activity points
1,509
Re: Matlab help

AliShariq said:
Hi, I'm new to Matlab and this Forum as well. Let me know if any one could help me out in passing arguments from one function to another in matlab or using some sort of global variables.

Any sort of help will be appreciated..

Regards,
Ali

Hello.
Create your functions in MatLab code, m-files. Don't forget to give the same name of the function to the saved file. For example,

"mar.m" file

function data_out=mar(data_in)
data_out=data_in*2; % double data_in

"deep.m" file

function out2=deepm(in2)
out2=mean(in2); % calculates the mean

After you have your functions done, you just have to call them in your main MatLab code file

clear all
close all
clc

data = 1:25; % vector
data2 = mar(data); % doubles values in "data" and stores it in "data2"
dataM = deep(data2); % calculates the mean of doubled "data", "data2"

Cheers,
mar_deepmode
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top