Matlab,文件夹中的高级循环和应用函数

发布于 2024-12-29 07:28:55 字数 307 浏览 2 评论 0原文

我编写了一段代码来分析视频文件,然后将数据绘制在图表上 将此图保存到 excel 和 jpg。

但我的问题是,我在大约 20 个文件夹中有超过 200 个视频需要分析,

因此我需要自动执行此代码以在文件夹内循环并分析其中的每个 *.avi 文件,并且

..所以任何想法或建议

非常感谢您的帮助

< strong>我需要知道如何循环文件夹并获取其中的文件,并对该文件夹中的这些文件应用函数

请注意,我的函数我也想将图形结果保存到 img,那么我应该包含完整的函数吗?保存时的路径?我该怎么做?

i wrote a code that analyze a video file and then plot data on a graph then
save this graph into
excel and jpg.

but my problem is that i have more than 200 video to analyze in around 20 folder,

so i need to automate this code to loop inside folders and analyze each *.avi file inside and

.. So any ideas or suggestions

Really appreciate your help

I need to know how to loop folders and get files inside and the apply a function to these files in that folder

Please note that my function that i also want to save graph result to img, should i then include full path while saving ? and how can i do it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2025-01-05 07:28:55

dirfullfile 命令就是您所需要的。根据您的目录结构,如下所示:

video_dir = 'videos';

% I'm not sure if there's a way to directly get a list of directories, but
% this will work
video_dir_children = dir(video_dir);
video_subdirs = [];
for ix = 1 : length(video_dir_children),
  % note we're careful to kick out '.' and '..' 
  %   (and any other directory starting with a '.')
  if(video_dir_children(ix).isdir && video_dir_children(ix).name(1) ~= '.')
    video_subdirs = [video_subdirs; video_dir_children(ix)];
  end
end

for ix = 1 : length(video_subdirs),
  this_dir = fullfile(video_dir, video_subdirs(ix).name);
  avi_files_in_this_dir = dir(fullfile(this_dir, '*.avi'));

  for jx = 1 : avi_files_in_this_dir,
    doVideoProcessing(fullfile(this_dir, avi_files_in_this_dir(jx).name));
  end

end

The dir and fullfile commands are what you need. Depending on your directory structure, something like this:

video_dir = 'videos';

% I'm not sure if there's a way to directly get a list of directories, but
% this will work
video_dir_children = dir(video_dir);
video_subdirs = [];
for ix = 1 : length(video_dir_children),
  % note we're careful to kick out '.' and '..' 
  %   (and any other directory starting with a '.')
  if(video_dir_children(ix).isdir && video_dir_children(ix).name(1) ~= '.')
    video_subdirs = [video_subdirs; video_dir_children(ix)];
  end
end

for ix = 1 : length(video_subdirs),
  this_dir = fullfile(video_dir, video_subdirs(ix).name);
  avi_files_in_this_dir = dir(fullfile(this_dir, '*.avi'));

  for jx = 1 : avi_files_in_this_dir,
    doVideoProcessing(fullfile(this_dir, avi_files_in_this_dir(jx).name));
  end

end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文