在Matlab中顺序保存.dat文件 [英] Sequence save of .dat files in matlab

查看:515
本文介绍了在Matlab中顺序保存.dat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将每个步骤的结果保存为序列格式.即

I try to save the each step results into sequence format. i.e.

cm_clusters_2_00001.dat
cm_clusters_2_00002.dat
cm_clusters_2_00003.dat
.
.
.
cm_clusters_2_00020.dat      

"particles_file_name"以正确的格式显示了所需的文件名,但是当保存该文件时,它会写"particles_file_name",这就是为什么我用相同的名称覆盖结果的原因.

"particles_file_name" show me the required file name in correct format but when it save that file it write "particles_file_name" and that is why i am over writing my results under the same name.

生成序列名称的部分代码:

Part of code which generate sequence names:

for kk= 1:20 
    if(kk<10)
        file_number = ['0000' int2str(kk)];
    elseif(kk>=10 && kk<100)
        file_number = ['000' int2str(kk)];
    elseif(kk>=100 && kk<1000)
        file_number = ['00' int2str(kk)];
    elseif(kk>=1000 && kk<10000)
        file_number = ['0' int2str(kk)];
    end

    particles_file_name = ['cm_clusters_2_' file_number '.dat'];

    save ('particles_file_name')

 end;

任何人都向我建议了如何保存这些文件的正确方法,因此不要用相同的名称覆盖它.如代码所示,正确的名称

any body suggest me the the correct way how to save these file so its not over written under the same name. As code show the correct name

 particles_file_name = ['cm_clusters_2_' file_number '.dat'];

,但保存错误.

推荐答案

您需要更改:

save('particles_file_name')

save(particles_file_name)

particles_file_name是具有更改的文件名的变量,因此您需要将其直接传递给save命令.相反,您正在做的是传递字符串'particles_file_name',该字符串与变量particles_file_name毫无关系.

particles_file_name is your variable with the changing file name, so you need to pass it directly to the save command. What you are doing instead is passing a string 'particles_file_name' which has no relation whatsoever with the variable particles_file_name.

这篇关于在Matlab中顺序保存.dat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆