只需要填写输入的路径与输出的路径即可。
clear all;clc;
root = 'C:\Users\ZRZ\Desktop\UATmat\';
dst = 'C:\Users\ZRZ\Desktop\UAT\';
if ~exist(dst, 'dir')
mkdir(dst);
end
% 下面这几句是为了获取一个目录下的txt文件名列表
fileFolder = fullfile(root);
dirOutput = dir(fullfile(fileFolder, '*.txt'));
fileNames={dirOutput.name}; % 1*100 cell
numFile = length(fileNames);
for idxFile = 1:numFile
path = [root fileNames{idxFile}];
res = load(path);
[seq_l, xywh] = size(res);
results{1}.res = res;
results{1}.type = 'rect';
results{1}.len = seq_l;
seq_name = fileNames{idxFile}(1:end-4);
sprintf(['now trans ' seq_name ' from txt to mat'])
% 将需要的结构体结果写成mat格式
save([dst seq_name '_UAT.mat'], 'results');
end
MATLAB脚本:txt文件到mat转换,
该脚本用于批量将指定目录下的txt文件转换为mat格式。首先,它检查目标保存目录是否存在,如果不存在则创建。接着,获取txt文件列表,读取每个文件内容,处理后存储为mat结构体,并保存到目标目录。
1万+

被折叠的 条评论
为什么被折叠?



