将数据和矩阵元素写入文本文件中的问题
我在将数据写入MATLAB中的文件时有问题,我有一个LP问题,即他们的解决方案是尺寸n的向量,我想在文本文件中写下有关此解决方案的一些信息,以随时阅读它, (我不想在MATLAB中保存工作空间) 我编写以下代码
n = 5;
Length = 10;
s = [1;0;1;0];
t = 0.6;
Test = fopen('Test.txt', 'w');
fprintf(Test,'TSP Problem Size is: %d \n', n);
fprintf(Test,'Optimal Length is: %.5f \n', Length);
fprintf(Test,'Time To Solve in seconds is: %f \n', t);
fprintf(Test,'Solution is: \n');
for i=1:size(s)
fprintf(Test,'%.0f\n', s(i));
end
fclose(Test);
,并且执行“ type(test.txt);”它看起来像我想要的 但是,当我在Windows Explorer中打开文件时,它似乎是一行,我不知道为什么??? 有什么方法可以继续格式化并在单独的行中编写每个值的解决方案 (我尝试DLMWRITE,但它只写矩阵,我需要写一些信息,然后写一些信息)
谢谢您的帮助
I have a problem with writing data to a file in Matlab, I have an LP problem that their solution is a vector of size n, and I want to write some information about this solution in a text file to read it any time I want,
(I don not want to save workspace in matlab)
I write the following code
n = 5;
Length = 10;
s = [1;0;1;0];
t = 0.6;
Test = fopen('Test.txt', 'w');
fprintf(Test,'TSP Problem Size is: %d \n', n);
fprintf(Test,'Optimal Length is: %.5f \n', Length);
fprintf(Test,'Time To Solve in seconds is: %f \n', t);
fprintf(Test,'Solution is: \n');
for i=1:size(s)
fprintf(Test,'%.0f\n', s(i));
end
fclose(Test);
and when I execute 'type(Test.txt);' it appears as I want
but when I open file in windows explorer it appears all as one line, I don't know why ???
is there any way to keep formatting and to write the solution every value in a separate line
(I try dlmwrite but it writes only matrix, I need to write some information then the matrix)
thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论