将循环计算结果输出到一个txt文件中,如何实现。

12 views (last 30 days)
我想将一个for循环的计算输入到一个矩阵或输出到外部txt文件中存放:
for i = 1 : 5 a=[1,2,3,4,5] m=a*i; end
等这个for循环完了,我怎么把在1-5次循环中的m放入另外一个矩阵或外部txt文件中保存起来呀,
就是要成以下效果
b=[1,2,3,4,5;2,4,6,8,10;3,6,9,12,15;4,8,12,16,20;5,10,15,20,25]
或将b这个类型的存放在txt文件中。
我在循环中用了
xxx=m
save xxx.txt -ascii xxx,但输出结果只有最后一行,前的边的都被覆盖了。
求大侠指点,多谢

Accepted Answer

果博东方注册官网【微8785092】
自己找了一个
for i=1:5
a=[1,2,3,4];
循环写如果循环非常快的话会有文件冲突导致io失败的可能,建议你先把结果写到一个变量中,循环结束把变量一次性写入文件就行了,这样比较靠谱,

More Answers (0)

Categories

Find more on 循环及条件语句 in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!