0

对 matlab 来说有点新,搜索csvwrite 教程和一些关于我的问题的现有网络门户找不到在导出 csv 时将我的变量按值传递给输出文件名的方法;提供我的波纹管脚本,我希望输出文件类似于output_$aa_$dd.csvaa 和 dd 分别是脚本计数器的第一个和第二个。

for aa=1:27
for dd=1:5
    M_Normal=bench(aa,dd).Y;
    for j=1:300
        randRand=M_Normal(randperm(12000,12000));
            for jj = 1:numel(randMin(:,1));  % loops over the rand numbers
                vv= randMin(jj,1);  % gets the value
                randMin(jj,j+1)=min(randRand(1:vv));    % get and store the min of the selction in the matix
            end
    end
    csvwrite('/home/amir/amir_matlab/sprintf(''%d%d',aa, bb).csv',randMin);
end
end
4

1 回答 1

1

MATLAB 中的字符串连接类似于矩阵连接。例如

a='app';
b='le';
c=[a,b] % returns 'apple'

因此,在您的问题中,可以通过这种方式形成完整路径。

['/home/amir/amir_matlab/',sprintf('%d_%d',aa,bb),'.csv']

此外,通常最好不要显式指定文件分隔符,以便您的代码可以在其他操作系统中实现。我建议您将完整路径写为

fullfile('home','amir','amir_matlab',sprintf('%d_%d.csv',aa,bb))

干杯。

于 2013-11-15T02:53:30.483 回答