2012-12-12 60 views
2

我在Matlab初學者,我需要幫助輸出我的X和Y這樣的形式座標:如何在Matlab中將數據保存爲特定格式的文本文件?

X-142232Y77639 
X-148878Y63979 
X-154215Y49757 
X-158196Y35097 

這是XY字符串列。 現在我有這樣的:

fileID = fopen('matrix.txt','a+'); 
formatSpec = 'x'%6.4f\n'; 
fprintf(fileID,'%6.4f\n'); 
fprintf(fileID,'%6.4f\n',x, y); 
fclose(fileID); 

在formatSpec我不知道如何添加Y' 謝謝!

回答

2

到您的格式字符串添加額外的令牌(%6.4f你的情況):(Documentation here

formatSpec = 'X%6.4fY%6.4f\n'; 

然後使用該格式字符串在您的通話fprintf

fprintf(fileID, formatSpec, x, y); 

+0

大。請投票並接受答案,如果這是你正在尋找的,並且是完整的。 – Geoff

相關問題