我必须在这个循环的开头添加什么?
如何使用 for 循环读取以下文件:(循环可以忽略文件名中的字符吗?)
abc-1.TXT
cde-2.TXT
Ser-3.TXT
wsz-4.TXT
aqz-5.TXT
iop-6.TXT
我必须在此循环的开头添加什么?
for i = 1:1:6
nom_fichier = strcat(['MyFile\.......' num2str(i) '.TXT']);
how I can read the following files using the for loop: (can the loop ignore the characters in filenames?)
abc-1.TXT
cde-2.TXT
ser-3.TXT
wsz-4.TXT
aqz-5.TXT
iop-6.TXT
What do I have to add at the beginning of this loop ??
for i = 1:1:6
nom_fichier = strcat(['MyFile\.......' num2str(i) '.TXT']);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 DIR 来避免构建文件名命令。例如:
You can avoid constructing the filenames by using the DIR command. For instance:
首先,为什么要在这里使用 strcat ?这本身就是一个单字符串。所有连接均已通过方括号 [] 完成。
接下来,我不确定你在这里问什么问题。是如何加载数据的吗?如果文件只是分隔的数字,每行的数量相同,则 load 足以加载它们,或者您可能需要文本读取。
我的猜测是您不知道如何构建文件名的主要部分。您可以这样做:
如果您不想通过输入名称来创建变量,则可以使用 dir,也许像这样创建文本文件名列表:
First of all, why would you use strcat here? This is, by itself, a SINGLE string. All concatenation has already been done by the brackets [].
Next, I'm not certain what is your question here. Is it how to load in the data? If the files are simply delimited numbers, with the same number of them on each line, then load will suffice to load them in, or perhaps you may need textread.
My guess is you do not know how to build the main part of of the file name. You might do it this way:
If you don't want to create a variable with the names by typing them in, then use dir, perhaps like this to create a list of text file names: