2011-08-26 84 views

回答

0

嘗試以下操作,動態生成的格式字符串,如果你不想要的數量%G \ t硬編碼

fstring = ''; 
repeats=5; 

for n=1:repeats 
fstring=[fstring,'%g\t']; 
end 
fstring = [fstring,'\r\n']; 

x=5; 
y=[repmat(x, 1, repeats)]; 
fn=fopen('A.txt', 'w'); 
fprintf(fn, fstring, y) 
0

你可以這樣做:

x=5; y=[repmat(x, 1, 5)]; 
save('A.txt', 'y' , '-ASCII'); 
+0

添加的解釋,而不是隻是代碼會有幫助... – eirikir

+0

保存命令只保存當前工作區中的所有變量,如果文件名存在,則保存覆蓋文件。它按原樣保存數據。 或者,你可以做(​​在你的上面的代碼): 'x = 5; y = [repmat(x,1,5)]; fn = fopen('A.txt','w'); fprintf(fn,'%g \ t',y)' –