2013-11-15 30 views
0

有點新的matlab在這裏,搜索csvwrite tutorial和一些現有的webportals有關我的問題找不到方法來傳遞我的變量的值輸出文件名稱,而在csv輸出時;提供我的bellow腳本,我想有輸出文件像output_$aa_$dd.csv其中aa和dd分別是腳本的計數器的第一個和第二個。csvwrite循環中帶有編號的文件名在matlab

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 

回答

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)) 

乾杯。

+0

乾杯好友;)我想我不得不提及輸出的矩陣以及最後,對吧? 'fullfile('home','amir','amir_matlab',sprintf('%d_%d.csv',aa,bb),randMin)' – Amir

+0

是的,作爲'csvwrite'的第二個參數。 – heriantolim