如何加载文件名存储在数组中的文件? [英] How do you load a file whose file name is stored in an array?

查看:93
本文介绍了如何加载文件名存储在数组中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

function [] = plotavg (x)
files = dir('*.mat');
for c=1:length(files)
    load files(c);
    d=0;
    if start_month == x
        for i=1:length(data)
            d = d + data(i);
        end
    end
end

我不知道如何编写它,以便装入功能装入数组的该索引中列出的文件

I don't know how to write it so that the load function loads the file listed in that index of the array

谢谢!

推荐答案

dir返回带有某些字段名称的结构.其中之一是名称",即文件名.如果您输入例如在控制台中的files(1)中,您将看到目录中每个项目的字段.

dir returns a struct with some field names. One of them is "name", i.e. the name of the file. If you type e.g. files(1) in the console, you will see the fields you get for each item in your directory.

替换

load files(c);

使用

load(files(c).name);

它应该可以工作.

这篇关于如何加载文件名存储在数组中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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