How to use syntax T = readtable(filename) for creating a table from a file?

I put the excel dataset file (.xlsx) with specific 'filename' in the Matlab projects saving path and then I used this syntax in command window
T = readtable(filename)
the program gives this error:
Undefined function or variable 'filename'
I'll be very grateful if suggest me a soloution

 Accepted Answer

try this
filename='c:\MyDoc\MyFile.xlsx';
T=readtable(filename);

3 Comments

Thanks for your useful suggestion I used it and a table (T) was created in my workspace, How can I compare all the rows of two variables of this table(the rows include words) by using counters? In general, Are these variables cell arrays or is it enough only to tell their names?
I am not sure what do you mean saying "by using counters". Once the table is created, you can reference it by ".",e.g. T.Name, T.Age. See "help table". There is an example data, run the example and check out patients.Age, patients.LastName, etc.
Thank you very much. About counters, I mean using nested for loops to compare two variables' data. I wanted to connect two columns in the dataset with each other(two variables in the table T) to form the edges between nodes.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!