Get output variable name from load function load in Matlab -
i want load ascii-file using syntax:
load('10-may-data.dat')
the returned output variable name should x10_may_data
.
is there way variable name in matlab? if want use regular expression translation, how can it? example, put x
before underscores or digits in filename , replace other non-alphabetic characters underscores.
the who
function returns names of variables in matlab. has built-in regexp selecting items:
x10_may_data = [1 2 3]; save x10_may_data.mat x10_may_data clear load x10_may_data.mat w = who('-regexp','x*') w = 'x10_may_data'
you can operate on w{1}
substitutions want. example, use strrep
function simple modifications of string:
newvar = strrep(w{1},'may','latest') newvar = x10_latest_data
for more complex modifications, use regexp
or regexprep
. when have new name, can assign eval
:
eval([newvar '=' w{1}]) % typing "x10_latest_data = x10_may_data" x10_latest_data = 1 2 3
[edit] ps agree comments eval
bad idea; need something done :) alternative approaches, see matlab page on topic.
Comments
Post a Comment