Matlab处理log文件

栏目: 编程工具 · 发布时间: 8年前

内容简介:Matlab处理log文件

一般文本类文件都用 javapython 处理方便很多,此处记录一下matlab 处理文本文件的一些语法。

例如,程序记录下的日志文件为:dl4ss_output.log_2017_03_10_210643,其部分内容为:

[Epoch: 1] - SDR:1.308344, SIR:2.063156, SAR:-1.509836, NSDR:2.908430  
Epoch 1/1  
50/50 [==============================] - 178s - loss: 1.9203 - val_loss: 1.7383  
Epoch 1/1  
50/50 [==============================] - 176s - loss: 1.6208 - val_loss: 1.5113  
Epoch 1/1  
50/50 [==============================] - 176s - loss: 1.4212 - val_loss: 1.3334  
Epoch 1/1  
50/50 [==============================] - 175s - loss: 1.2612 - val_loss: 1.1911  
Epoch 1/1  
50/50 [==============================] - 176s - loss: 1.1320 - val_loss: 1.0740  
[Epoch: 6] - SDR:2.128937, SIR:3.154744, SAR:0.774681, NSDR:3.729023  
Epoch 1/1  
50/50 [==============================] - 175s - loss: 1.0312 - val_loss: 0.9913  

现在想对该日志文件进行处理,并将Epoch迭代过程中评估的结果值绘制成图,方法如下:

clc   
clear  
colours = ’rbckgcmbkgcmbkgcmbgrcmykbgrcmykb’;  % ’bgrcmykw’ modified by jacoxu@msn.com   
symbols = ’.x^os*.dvph><x+^os*.dvph><+’;  % ’.ox+*sdv^<>ph’ %参考 http://blog.sina.com.cn/s/blog_618af1950100kdi2.html   
linetypes = {‘-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’,'-’};  % {‘-’,':’,'-.’,'–’}   
figureSize = [300,200,500,300];   
lineWidth = 1.5;   
para_list = {‘SDR’, ’SIR’, ’SAR’, ’NSDR’};   
  
log_file = ’dl4ss_output.log_2017_03_10_210643′;   
log_file_fd = fopen(log_file);   
epoch_idx = 0;   
epoch_num = [];   
sdr_value = [];   
sir_value = [];   
sar_value = [];   
nsdr_value = [];   
  
% 开始循环读取log文件   
while true   
    % 获取当前行内容   
    line = fgets(log_file_fd);   
    % 如果当前行没有内容了   
    if ischar(line) == false   
        break  
    end   
    % 判断当前行中是否有评估值   
    if isempty(strfind(line, ’NSDR:’))   
        continue  
    end   
    epoch_idx = epoch_idx + 1;   
    results = regexp(line, ’ - ’, ’split’);   
    % 先获取当前的Epoch_num   
    epoch_num(epoch_idx) = str2double(results{1}(8:(length(results{1})-1)));   
    % 开始解析SDR, SIR, SAR 和 NSDR 值   
    results = results{2};   
    results = regexp(results, ’, ’, ’split’);   
    for idx = 1:length(results)   
        tmp_results = regexp(results{idx}, ’:', ’split’);   
        if strcmp(tmp_results{1}, ’SDR’)   
            sdr_value(epoch_idx) = str2double(tmp_results{2});   
        elseif strcmp(tmp_results{1}, ’SIR’)   
            sir_value(epoch_idx) = str2double(tmp_results{2});   
        elseif strcmp(tmp_results{1}, ’SAR’)   
            sar_value(epoch_idx) = str2double(tmp_results{2});   
        elseif strcmp(tmp_results{1}, ’NSDR’)   
            nsdr_value(epoch_idx) = str2double(tmp_results{2});   
        else  
            print (‘Error eval item’)   
        end   
    end   
end   
  
% 绘图   
figure(‘position’, figureSize)   
plot(epoch_num, sdr_value, [colours(1), symbols(1), char(linetypes(1))], ’linewidth’, lineWidth);   
hold on;   
plot(epoch_num, sir_value, [colours(2), symbols(1), char(linetypes(2))], ’linewidth’, lineWidth);   
hold on;   
plot(epoch_num, sar_value, [colours(3), symbols(1), char(linetypes(3))], ’linewidth’, lineWidth);   
hold on;   
plot(epoch_num, nsdr_value, [colours(4), symbols(1), char(linetypes(4))], ’linewidth’, lineWidth);   
title(‘BSS\_Eval results’)   
grid on;   
xlabel(‘Epoch Number’)   
ylabel(‘Value’)   
axis([0 epoch_num(end) -2 5]);   
legend(para_list, ’Location’, ’SouthEast’)   

绘制的结果如下:

Matlab处理log文件


以上所述就是小编给大家介绍的《Matlab处理log文件》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Usability for the Web

Usability for the Web

Tom Brinck、Darren Gergle、Scott D. Wood / Morgan Kaufmann / 2001-10-15 / USD 65.95

Every stage in the design of a new web site is an opportunity to meet or miss deadlines and budgetary goals. Every stage is an opportunity to boost or undercut the site's usability. Thi......一起来看看 《Usability for the Web》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换