How to get the output variable name in the load() in matlab?

14 次查看(过去 30 天)
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

回答(2 个)

Walter Roberson
Walter Roberson 2016-2-3
genvarname(regexprep('10-May-data', '-', '_'))
But you should not be using dynamically generated names as the names of variables.

Steven Lord
Steven Lord 2016-2-3
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');

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by