Can one save the filename as a variable in 'readtable'?
Show older comments
Suppose I use
T=readtable('texas,csv')
I want to save the name of the file (texas) as a variable. Please advise.
1 Comment
alpedhuez
on 29 Nov 2020
Accepted Answer
More Answers (1)
Ameer Hamza
on 28 Nov 2020
Edited: Ameer Hamza
on 28 Nov 2020
you can save char arrays in a variable and then concatenate it with the extension using [] operator.
filename = 'texas';
T = readtable([T '.csv'])
5 Comments
alpedhuez
on 28 Nov 2020
Ameer Hamza
on 28 Nov 2020
You can use fileparts()
filename = 'texas.csv';
[~, name, ext] = fileparts(filename)
alpedhuez
on 28 Nov 2020
Ameer Hamza
on 29 Nov 2020
Are you trying to name the variables named like texas, iowa, etc. For example
filename = 'texas';
texas = readtable([T '.csv'])
This is not a good coding approach: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval
alpedhuez
on 29 Nov 2020
Categories
Find more on MATLAB Compiler SDK 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!