MATLAB Answers

How to read several files and save CSV files in folder

12 ビュー (過去 30 日間)
Kong
Kong 2020 年 3 月 12 日
コメント済み: Kong 2020 年 3 月 12 日
Hello. I am a beginner in Matlab.
I have several video files (daria_bend.avi, denis_bend.avi, eli_bend.avi, .......).
I want to read each file and save it to the CSV file.
I have a code, but I want to use "for loop" to read without entering each name of the file.
How to fix two parts.
reader = VideoReader('shahar_bend.avi');
csvwrite('shahar_bend_file.csv',X);
All code / I should enter each file name.
clear all
close all
%// read the video:
reader = VideoReader('shahar_bend.avi');
vid = {};
while hasFrame(reader)
vid{end+1} = im2single(readFrame(reader));
end
%// simple background estimation using mean:
bg = mean( cat(4, vid{:}), 4);
%// estimate foreground as deviation from estimated background:
for i=1:30
fIdx(i) = i; %// do it for frame 1 ~ 60
fg{i} = sum( abs( vid{fIdx(i)} - bg ), 3 );
fg{i} = imresize(fg{i}, 0.5);
fg{i} = reshape(fg{i},[],1);
end
X = cell2mat(fg);
csvwrite('shahar_bend_file.csv',X);

  0 件のコメント

サインイン to comment.

採用された回答

Jon
Jon 2020 年 3 月 12 日
編集済み: Jon 2020 年 3 月 12 日
You can use
list = dir('*.avi')
to get a list of the .avi files in your local director. Check out the documentation on the dir command for details.
It return an array of structures. Specifically you can make a loop like
% get a list of the .avi files
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list.name(k));
% and so on
end

  3 件のコメント

Kong
Kong 2020 年 3 月 12 日
Thank you so much!
I got this error.
clear all
close all
%// read the video:
list = dir('*.avi')
% loop through the filenames in the list
for k = 1:length(list)
reader = VideoReader(list.name(k));
end
Jon
Jon 2020 年 3 月 12 日
oops it should be
reader = VideoReader(list(k).name);
sorry about that
Kong
Kong 2020 年 3 月 12 日
Thank you so much!
Can I get another idea to make CSV each file?
csvwrite('shahar_bend_file.csv',X);

サインイン to comment.

その他の回答 (0 件)

サインイン してこの質問に回答します。


Translated by