matlab可以导出java文件吗_如何在Matlab中导入和保存多个文本文件,为每个文件创建一个Matrix...

我想你知道所有文件夹所在的基本路径 . 然后你可以使用这样的东西:

% First find all folders

folders = cell(0); % empty cell to save folder names

nFolders = 0;

allFolders = ls(basePath); % find all files and folders

for k=1:size(allFolders,1)

curFolder = fullfile(basePath,strtrim(allFolders(k,:)));

if isdir(curFolder) % find out if it is a folder

if ~(allFolders(k,1) == '.') % ignore '.' and '..'

folders{nFolders+1,1} = curFolder; % Save folder path

nFolders = nFolders + 1;

end

end

end

% Then find all files inside these folders

files = cell(0); % empty cell array for file names

nFiles = 0;

for k=1:nFolders % go through all folders

allFiles = ls(folders{k,1});

for l=1:size(allFiles,1) % go through all found files/subfolders

curFile = fullfile(folders{k},strtrim(allFiles(l,:)));

if ~isdir(curFile) % only select files

files{nFiles+1,1} = curFile; % and save it to the cell

nFiles = nFiles + 1;

end

end

end

现在,您可以遍历 files 单元格并根据您的脚本读取所有文件 . 我看到你对文件名感兴趣 . 您可以通过提取文件名

[path,filename,extension] = fileparts(files{k,1});

要导入文本文件,您可以使用 dlmread ,我认为它比 textscan 更直观(但当然有更多限制) . 为此,您不必使用 fopen 打开文件,您可以直接提供文件名 .

value = dlmread(fileName,' ',[23,13,23,13]);

分隔符现在是一个空格,只读取row = 23 / col = 13的值 . 请注意,范围从row / col = 0开始,而不是像Matlab中通常那样1 - 所以也许你必须将它改为 [22,12,22,12] .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值