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

17 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

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

Steven Lord
Steven Lord il 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');

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by