How can I pass the filename as a coefficient in function ?
1 view (last 30 days)
Show older comments
I would like to use a excel filename as a coefficient as below :
function [ic, is] = Indexing(filename) % such as a.xlsx
[num, txt, raw] = xlsread(filename);
[rownum, colnum] = size(raw);
but, I met the error message which is "Reference to a cleared variable filename."
Error in Indexing (line ) [num, txt, raw] = xlsread(filename);
How can I acheive this in Matlab.
Thank you.
0 Comments
Answers (1)
Star Strider
on 3 Apr 2015
You have to assign your ‘filename’ variable the name of the spreadsheet you want your ‘Indexing’ function to read:
filename = 'MySpreadsheet.xls';
[ic, is] = Indexing(filename);
This assumes the file is in your MATLAB search path. If it is not, you also have to supply the full path to the file, as well as the name of the file.
2 Comments
Star Strider
on 3 Apr 2015
I am not sure I understand. If you want xlsread to actually read a file, you have to tell it what file you want it to read.
In your code, ‘filename’ is a variable, so it has to have something assigned to it in order for you to use it in your code. That assignment should be a string with the name of the file you want to use, as in my example.
See Also
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!