How to get the output variable name in the load() in matlab?
14 views (last 30 days)
Show older comments
I want to load an ascii-file using this syntax:
load('10-May-data.dat').
The returned output variable name should be X10_May_data.
Is there a way to get the variable name in matlab?
If I want to use regular expression to do the translation, how can I do it? For example, put an X before any underscores or digits in filename and replaces any other non alphabetic characters with underscores.
Thanks
0 Comments
Answers (2)
Walter Roberson
on 3 Feb 2016
genvarname(regexprep('10-May-data', '-', '_'))
But you should not be using dynamically generated names as the names of variables.
Steven Lord
on 3 Feb 2016
The easiest and safest way is to call LOAD with an output argument so you know at the time you write your code what the variable name will be.
mydata = load('10-May-data.dat');
0 Comments
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!