且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Matlab中的变量变量

更新时间:2023-11-25 07:49:45

要将变量放入基本工作区,请使用 assignin

  assignin ('base',v,qdata); 

正如您在 assignin documentation ,对于您可能要使用的某些分配案例 evalin


I have 30 txt files with data And I want to create on the fly vectors from that files with the name of "file name"

pathforindependents = 'C:\MatLab\independent\'

independents = dir(fullfile(pathforindependents,'ind*.txt'))              

for i = 1:length(independents)

    filename = independents(i).name;
    r=regexp(filename,'\.','split');
    qnumber = r(2)
    qtitle=r(3)

    qpath = strcat(pathforindependents,filename)
    qdata = load(qpath)

    mtrxPrefix = 'mtrx_';

    v = strcat(mtrxPrefix,qtitle);

    eval(???????????????????????)

end

But I dont know how can I do it. No matter what I try Matlab gives me "Undefined function 'eval' for input arguments of type 'cell'." Error?

My data file structure is like

ind.01.AGE.txt

0
1
0
0
0
1
1
0
1
...

At the end I want to reach this

mtrx_AGE =
0
1
0
0
0
1
1
0
1
...

How can I do it ? Thank you.

To put the variables in the base workspace, use assignin:

 assignin('base', v, qdata);

As you can see in the assignin documentation, for certain assignment cases you may want to use evalin.