txt文件转换为matlab文件。我主要是在使用目标跟踪工具箱画图的时候使用

该脚本用于批量将指定目录下的txt文件转换为mat格式。首先,它检查目标保存目录是否存在,如果不存在则创建。接着,获取txt文件列表,读取每个文件内容,处理后存储为mat结构体,并保存到目标目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

只需要填写输入的路径与输出的路径即可。

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值