How can I pass the filename as a coefficient in function ?
Ältere Kommentare anzeigen
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.
Antworten (1)
Star Strider
am 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 Kommentare
Heejun Yoo
am 3 Apr. 2015
Bearbeitet: Heejun Yoo
am 3 Apr. 2015
Star Strider
am 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.
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!