阅读变量内容

时间:2014-03-19 06:06:32

标签: matlab variables

我有大量的变量上传到MATLAB工作区。现在我需要通过FOR循环调用它们,例如,我需要调用变量VAR_10_V并读取其内容并对其执行某些操作。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

在这种情况下的一个好习惯是将存储在'mat'文件中的变量作为结构加载(而不是作为独立变量)

ld = load( 'myMatFile.mat' ); % load into struct ld
varNames = fieldnames( ld ); % get the names of all variables
for ii = 1:numel( varNames )
    vn = varNames{ii}; % the variable name
    ld.(vn); % its value
    % do something with ld.(vn) here...
end