Continue to Site

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
 

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
 

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).
 

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
 

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
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top