如何在递归函数中将数据存储在文本文件中 [英] How Can I Store Data On A Text File In Recursive Function
本文介绍了如何在递归函数中将数据存储在文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在尝试在Matlab中运行递归函数时将数据添加到文件中
但不幸的是,在dlmwrite()中添加文本文件中的数据时功能只是添加了最后一个数据。
以下代码是我的代码
hi all
I am trying add my data to a file during run of a recursive function in Matlab
but unfortunately while adding data in text file by dlmwrite() function just the last data was added.
the below code is my code
for i=1:7
dlmwrite('m.txt',i);
end
谢谢大家。
thanks all.
推荐答案
快速查看文档会告诉你问题是什么。
http://uk.mathworks.com/help/matlab/ref/dlmwrite.html [ ^ ]
dlmwrite(filename,M)将数组M中的数字数据写入ASCII格式文件,fil ename,使用默认分隔符(,)分隔数组元素。如果文件,文件名已经存在,dlmwrite将覆盖该文件。
而是使用:
dlmwrite(filename,M,' - append')将数据附加到现有文件的末尾,filename。
A quick look at the documentation would have told you what the problem was.
http://uk.mathworks.com/help/matlab/ref/dlmwrite.html[^]
dlmwrite(filename,M) writes numeric data in array M to an ASCII format file, filename, using the default delimiter (,) to separate array elements. If the file, filename, already exists, dlmwrite overwrites the file.
Instead use:
dlmwrite(filename,M,'-append') appends the data to the end of the existing file, filename.
这篇关于如何在递归函数中将数据存储在文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文