Write a function with input .xls file to read'
显示 更早的评论
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
回答(2 个)
function Econometric = Analysis(filename)
Stock = xlsread(filename,1,'B2:B263')
... the rest of your code
end
Star Strider
2016-7-6
编辑:Star Strider
2016-7-6
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 个评论
polar
2016-7-6
Star Strider
2016-7-6
It depends on how you wrote your function.
I don’t have all your code, but you could be creating a conflict with:
Function Econometric = Analysis(Stock)
and:
Stock=xlsread('nameofstock.xls',1,'B2:B263')
That would replace your input variable ‘Stock’ with the result of the file read operation.
I would do something similar to:
StockData = xlsread(Stock,1,'B2:B263');
instead.
polar
2016-7-6
Star Strider
2016-7-6
My pleasure!
类别
在 帮助中心 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!