是否可以创建通过文件名模式过滤文件的mat文件的filedatastore? 到目前为止,我明白了:
private func setupView()
{
let path = URL(fileURLWithPath: Bundle.main.path(forResource: "mydogwalkvideo", ofType: ".mp4")!)
let player = AVPlayer(url: path)
let newLayer = AVPlayerLayer(player: player)
newLayer.frame = self.videoView.frame
self.videoView.layer.addSublayer(newLayer)
newLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill //It's set to resize aspect to fill
player.play()
player.actionAtItemEnd = AVPlayer.ActionAtItemEnd.none
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.videoDidPlayToEnd(notification:)), name: NSNotification.Name(rawValue: "AVPlayerItemDidPlayToEndTimeNotification"), object: player.currentItem)
}
@objc func videoDidPlayToEnd(notification: Notification)
{
let player: AVPlayerItem = notification.object as! AVPlayerItem
player.seek(to: CMTime.zero)
}
但是我将不使用的一些mat文件很大,因此减慢了该过程。 我无法将所有文件移动到1个目录,因为我的目录结构如下:
fds = fileDatastore(dir_save,'ReadFcn',@load,'FileExtensions','.mat','IncludeSubfolders',true);
f=1;
while hasdata(fds)
disp(num2str(progress(fds)*100)
dataarray = read(fds);
if ~isempty(strfind(fds.Files{f},myPattern))
%% do somthing
end
f=f+1;
end
答案 0 :(得分:1)
您可以在对fullfile的呼叫中使用通配符。 使用fileDatastore文档中的示例:
% No filtering
>> fds = fileDatastore(fullfile(matlabroot,'toolbox','matlab','demos'),'ReadFcn',@load,'FileExtensions','.mat')
fds =
FileDatastore with properties:
Files: {
'E:\MATLAB64\R2018b\toolbox\matlab\demos\accidents.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\airfoil.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\airlineResults.mat'
... and 37 more
}
UniformRead: 0
ReadFcn: @load
AlternateFileSystemRoots: {}
% Filtering for .mat files starting with "w"
>> fds =
fileDatastore(fullfile(matlabroot,'toolbox','matlab','demos','w*'),'ReadFcn',@load,'FileExtensions','.mat')
fds =
FileDatastore with properties:
Files: {
'E:\MATLAB64\R2018b\toolbox\matlab\demos\west0479.mat';
'E:\MATLAB64\R2018b\toolbox\matlab\demos\wind.mat'
}
UniformRead: 0
ReadFcn: @load
AlternateFileSystemRoots: {}
要检查不同的文件夹,请使用两个通配符:
>> !mkdir d01
>> !mkdir d02
>> !touch d01/file1.mat
>> !touch d01/myPatternFile.mat
>> !touch d02/file2.mat
>> !touch d02/myPatternFile.mat
>> fileDatastore(fullfile(pwd,'d*\myPattern*'),'ReadFcn',@load,'FileExtensions','.mat')
ans =
FileDatastore with properties:
Files: {
'H:\Documents\56133896\d01\myPatternFile.mat';
'H:\Documents\56133896\d02\myPatternFile.mat'
}
UniformRead: 0
ReadFcn: @load
AlternateFileSystemRoots: {}