本文介绍了在Matlab中的变量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有30个带有数据的txt文件,而且我想用名称为文件名称的文件从这个文件中创建矢量 $ b $ independents = dir(fullfile(pathforindedentdents,'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(???????????????????????) 结束 但我不知道该怎么做。无论我尝试Matlab给我未定义函数'eval'输入参数的类型'单元格'。错误? 我的数据文件结构像 ind.01.AGE.txt 0 1 0 0 0 1 1 0 1 ... 最后,我想达到这个目的。 mtrx_AGE = 0 1 0 0 0 1 1 0 1 ... 我该怎么办?谢谢。解决方案要将变量放入基本工作区,请使用 assignin : assignin ('base',v,qdata); 正如您在 assignin documentation ,对于您可能要使用的某些分配案例 evalin 。 I have 30 txt files with dataAnd 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(???????????????????????)endBut 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 likeind.01.AGE.txt010001101...At the end I want to reach thismtrx_AGE =010001101...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. 这篇关于在Matlab中的变量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-16 03:19