Write a function with input .xls file to read'

4 visualizaciones (últimos 30 días)
polar
polar el 6 de Jul. de 2016
Comentada: Star Strider el 6 de Jul. de 2016
Hi, I'm writing a function (not a '.m' script) that allows me to make a series of econometric tests on a pair of stocks. My input should be the name of the excel file to read. More specifically, my idea is: Function Econometric= Analysis(Stock). The following first line of the code that I wrote was Stock=xlsread('nameofstock.xls',1,'B2:B263'). Unfortunately it doesn't work. I know all other following lines are ok but without first line...everything is useless. Can you help me? Thanks

Respuestas (2)

Stephen23
Stephen23 el 6 de Jul. de 2016
Editada: Stephen23 el 6 de Jul. de 2016
function Econometric = Analysis(filename)
Stock = xlsread(filename,1,'B2:B263')
... the rest of your code
end
As explained in the function documentation, and also covered in the introductory tutorials:
  2 comentarios
polar
polar el 6 de Jul. de 2016
Yes I tried this but it shows this error: "Undefined function 'analysis' for input arguments of type 'char'.
Stephen23
Stephen23 el 6 de Jul. de 2016
Editada: Stephen23 el 6 de Jul. de 2016
MATLAB is case sensitive. Your function is called Analysis, but your error message tells us that you are calling analysis. You need to make up your mind which one you are going to use!

Iniciar sesión para comentar.


Star Strider
Star Strider el 6 de Jul. de 2016
Editada: Star Strider el 6 de Jul. de 2016
The xlsread function is going to assume that ‘nameofstock.xls’ in this line is the file name you want to read, because of the single quotes:
Stock=xlsread('nameofstock.xls',1,'B2:B263');
If ‘nameofstock.xls’ is already a string, you don’t need the quotes.
----------------------------
EDIT ‘Yes I tried this but it shows this error: "Undefined function 'analysis' for input arguments of type 'char'.’
You named your function ‘Analysis’ but called it as ‘analysis’. MATLAB is case-sensitive, so ‘Analysis’ is not the same as ‘analysis’.
Call it as:
Econometric= Analysis(Stock);
and you will not get that error.
  4 comentarios
polar
polar el 6 de Jul. de 2016
YESSSSS I DID!!!! MY mistake: I previoulsy changed the name of the function from "analysis" to another name and obviously Matlab didn't recognized it. Thanks mate!
Star Strider
Star Strider el 6 de Jul. de 2016
My pleasure!

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by