在MATLAB中的for循环中加载文件 [英] Loading files in a for loop in matlab

查看:71
本文介绍了在MATLAB中的for循环中加载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在for循环内加载matlab向量中包含的不同文件名.我写了以下内容:

I am trying to load different file names contained in a matlab vector inside a for loop. I wrote the following:

fileNames = ['fileName1.mat', ..., 'fileName_n.mat'];
for i=1:n
    load(fileNames(i))
    ...
end

但是,它不起作用,因为 fileNames(i)仅返回文件名的首字母.

However, it doesn't work because fileNames(i) returns the first letter of the filename only.

如何提供完整的文件名作为加载参数(文件名字符串的大小可能会有所不同)

How can I give the full file name as argument to load (the size of the string of the filename can vary)

推荐答案

使用单元格而不是数组.

Use a cell instead of an array.

fileNames = {'fileName1.mat', ..., 'fileName_n.mat'};

原则上,您的代码是一只猫,只给您一个字符串(因为字符串是字符数组).

Your code is in principle a string cat, giving you just one string (since strings are arrays of characters).

for i=1:n
    load(fileNames{i})
    ...
end

使用 {} 代替括号.

这篇关于在MATLAB中的for循环中加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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