Got Questions? Get Answers.
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

Thread Subject:
2 quick questions: How do I make a function that will use an input parameter to open a file?

Subject: 2 quick questions: How do I make a function that will use an input parameter to open a file?

From: Laurentiu Galan

Date: 11 Dec, 2010 03:03:04

Message: 1 of 2

I am currently running the function
[Sharpe, Win%, Loss%, CumRet] = pairtrade(lcap,scap,lentry,sentry,k,f)
I want to change this function to:
[Sharpe, Win%, Loss%, CumRet] = pairtrade(lcap,scap,lentry,sentry,k,f, PEP)
so that when i run this function the very next line is:
fid=fopen('V:\Desktop\PEP.csv')
This is already saved in 'V:\Desktop\PEP.csv
However, I want this as a variable so that if I do:
[Sharpe, Win%, Loss%, CumRet] = pairtrade(lcap,scap,lentry,sentry,k,f, KO)
the very next line will be
fid=fopen('V:\Desktop\KO.csv')
Basically I want the ending to the V:\Desktop\KO.csv to be a variable.

Also, how do I take take the mean and standard deviation of a matrix A in pieces without loops. i.e. if I want the mean of a n x 1 matrix only for the values 55 to the end? Same with standard deviation. Can I do: mean(A(55:end,1)) and std(A(55:end,1))

Thanks a lot and happy holidays!

Subject: 2 quick questions: How do I make a function that will use an

From: Walter Roberson

Date: 11 Dec, 2010 03:16:36

Message: 2 of 2

On 10/12/10 9:03 PM, Laurentiu Galan wrote:
> I am currently running the function [Sharpe, Win%, Loss%, CumRet] =
> pairtrade(lcap,scap,lentry,sentry,k,f)
> I want to change this function to:
> [Sharpe, Win%, Loss%, CumRet] = pairtrade(lcap,scap,lentry,sentry,k,f, PEP)
> so that when i run this function the very next line is:
> fid=fopen('V:\Desktop\PEP.csv')
> This is already saved in 'V:\Desktop\PEP.csv
> However, I want this as a variable so that if I do:
> [Sharpe, Win%, Loss%, CumRet] = pairtrade(lcap,scap,lentry,sentry,k,f, KO)
> the very next line will be
> fid=fopen('V:\Desktop\KO.csv')
> Basically I want the ending to the V:\Desktop\KO.csv to be a variable.

That isn't going to work, because PEP and KO are not defined variables.
A variable has to have a definition in order to appear in an argument
list for a function call.

What would work is if instead the parameter was 'PEP' and 'KO' each in
quotes.

fid = fopen(sprintf('V:\\Desktop\\%s.csv', FileNameVariable));

> Also, how do I take take the mean and standard deviation of a matrix A
> in pieces without loops. i.e. if I want the mean of a n x 1 matrix only
> for the values 55 to the end? Same with standard deviation. Can I do:
> mean(A(55:end,1)) and std(A(55:end,1))

Yes, just like that.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us