美文网首页
matlab 文件操作函数总结

matlab 文件操作函数总结

作者: 青帝花神 | 来源:发表于2016-08-29 14:24 被阅读0次

1.fgetl(fp) 整行读取文件。

returns the next line of the specified file,removing the newline characters . 如果 return value contains only the end-of-file marker ,the value is -1

        fid = fopen(logName, 'r');          
        fid_accuracy = fopen('output_accuracy.txt', 'w');       
        fid_loss = fopen('output_loss.txt', 'w');tline = fgetl(fid);

2.disp(tline) 显示内容

3.strfind(a,b) 从串a中,寻找子串b

示例代码:

  %function : get the accuracy array from the caffe train log , the log is
  %stored when we train our model.
  clc;
  clear;

  % log file of caffe model
  logName = 'rgb_log.txt';

  fid = fopen(logName, 'r');
  fid_accuracy = fopen('output_accuracy.txt', 'w');
  fid_loss = fopen('output_loss.txt', 'w');

  tline = fgetl(fid);
  while ischar(tline)
  % First find the loss line
  k1 = strfind(tline, 'Iteration');
  if (k1)
     indexStart = k1 + 10;
     indexEnd = strfind(tline, ',') - 1;
     str2 = tline(indexStart:indexEnd);
     k2 = strfind(tline, 'loss');
     if (k2)
         indexStart = k2 + 7;
         indexEnd = size(tline);
         str1 = tline(indexStart:indexEnd(2));
         res_str1 = strcat(str2, '/', str1);
         fprintf(fid_loss, '%s\r\n', res_str1);
     end
  end
  % First find the accuracy line
  k3 = strfind(tline, 'Test net output');
  if (k3)
      k4 = strfind(tline, 'accuracy');
      if (k4)
          % If the string contain test and accuracy at the same time
          % The bias from 'accuracy' to the float number
          indexStart = k4 + 11; 
          indexEnd = size(tline);
          str = tline(indexStart : indexEnd(2));  %%%%get the accurary
        
        
          % Concatenation of two string
          res_str = strcat(str2, '/', str);
          fprintf(fid_accuracy, '%s\r\n', res_str);
      end        
  end

  tline = fgetl(fid);

  %%%%train net loss  and test net loss 

  end

fclose(fid);
fclose(fid_accuracy);

相关文章

  • matlab 文件操作函数总结

    1.fgetl(fp) 整行读取文件。 returns the next line of the spec...

  • Python 操作 HDF5文件

    在Matlab操作HDF5文件中已经详细介绍了HDF5文件已经利用Matlab对其进行操作的方法。这篇文章总结一下...

  • Matlab中流场显示

    Matlab有个volvec.m文件专门总结了流体后处理函数,里面有画流线或流管方法。 选择把数据从matlab导...

  • MATLAB|随手经常用的小代码集合地

    文件操作 判断某个文件或者文件夹等是否存在MATLAB中exist()函数可以用于判定某文件名,变量,路径和类等是...

  • matlab技巧和快捷键

    Matlab常用小技巧及部分快捷键 Matlab常用小技巧一: 1. m文件如果是函数,保存的文件名最好与函数名一...

  • Matlab 简单图像处理

    一、图像处理的基本操作 1.从图形文件读取图像 通过 matlab 自带的 imread 读入图像,函数内为图像的...

  • 21-R语言文件系统操作函数

    1、 文件操作函数概览 2、文件夹操作函数概览 3、文件操作函数 3.1 创建文件 3.2 检查文件是否存在 3....

  • 2019-06-16 IO文件操作---C语言

    Linux下普通IO文件操作---C语言 普通文件IO总结 FILE结构体 打开文件fopen函数 文件指针名=f...

  • 学习系统编程总结

    1,文件操作 1.1普通文件操作: 使用open函数创建函数 函数功能:打开文件函数参数:pathname:待打开...

  • Python基础梳理

    自己的学习总结,关于python。 总结的基本逻辑是:元素——集合——语句——函数——集——文件操作——随机数生成...

网友评论

      本文标题:matlab 文件操作函数总结

      本文链接:https://www.haomeiwen.com/subject/zshxettx.html