我是 Matlab 初学者,我需要帮助以这种格式输出我的 X 和 Y 坐标:
X-142232Y77639
X-148878Y63979
X-154215Y49757
X-158196Y35097
它是一列 X
和 Y
字符串。
现在我有这个:
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? 谢谢!
最佳答案
将其他标记(在您的情况下为 %6.4f
)添加到您的格式字符串中:
formatSpec = 'X%6.4fY%6.4f\n';
然后在调用 fprintf
fprintf(fileID, formatSpec, x, y);
( Documentation here .)
关于file - Matlab中如何将数据保存到特定格式的文本文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13848258/