如何在Matlab中使用多个文件(同一目录中的不同文件名)运行相同的代码? [英] How to run the same code with many files (different file name in same directory) in Matlab?

查看:29
本文介绍了如何在Matlab中使用多个文件(同一目录中的不同文件名)运行相同的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一千个 .dat 文件可以用同一个程序运行.有没有更快的方法或脚本来自动运行它而不是一个一个地运行它们?.dat 文件具有不同的文件名.

I have a thousand .dat files to run with the same program. Is there any faster way or script to run it automatically instead of run them one by one? The .dat files have different filenames.

该程序类似于:

fid=fopen('**abd**.dat');
C=textscan(...);
...
save('**abd**.txt',data);

abd 是文件名.我有数千个不同文件名的文件.不断将这些文件名复制并粘贴到程序中并运行它,这有点烦人.有人有更快的方法或代码吗?

The abd is the file name. I have thousands of files with different file names. It is a bit annoying by keep copying and pasting those filenames into the program and run it. Anyone got a faster way or code for this?

推荐答案

您可以使用dir"来获取文件列表,然后像这样循环处理它们.

you can use "dir" to get a list of files, and then process them in a loop like this.

fns = dir('*.dat');
for i = 1:length(fns)
    fid = fopen(fns(i).name);
    C = textscan(...);
    fclose(fid);
    save([fns(i).name,'.dat'],data);

end

这篇关于如何在Matlab中使用多个文件(同一目录中的不同文件名)运行相同的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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