如何在 MATLAB 中一步加载具有相似名称和/或字符串的 100 个文件? [英] How can I load 100 files with similar names and/or string in just one step in MATLAB?
本文介绍了如何在 MATLAB 中一步加载具有相似名称和/或字符串的 100 个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目录中有 100 个 ASCII 文件,名称如下:
I have 100 ASCII files in my directory all named as follows:
int_001.ASC
int_002.ASC
int_003.ASC
.
.
.
int_099.ASC
int_100.ASC
int_001.ASC
int_002.ASC
int_003.ASC
.
.
.
int_099.ASC
int_100.ASC
我必须使用 importdata 将它们全部导入到 MATLAB 中,其工作方式如下:
I have to import them in MATLAB all with importdata, which should work as follows:
A = importdata('int_001.ASC', ' ', 9)
x = A.data(:,1)
y = A.data(:,2)
我的问题是:如何避免写入 100 次 importdata
?有没有办法只写第一个字符串然后上传所有数据?
My question is: how can I avoid writing 100 times importdata
? Is there a way to write the first string only and then have all data uploaded?
谢谢
推荐答案
fls = dir( 'int_*.ASC' );
for fi=1:numel(fls)
A{fi} = importdata( fls(fi).name, ' ', 9 );
% ...
end
更新:
您可以使用字符串格式来读取文件到他们的数字:
UPDATE:
You may use string formatting to read the files according to their numbers:
for fi=1:100
A{fi} = importdata( sprintf('int_%03d.ASC', fi ), ' ', 9 );
% ...
end
这篇关于如何在 MATLAB 中一步加载具有相似名称和/或字符串的 100 个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文