matlab批量合并txt文件
1: %% merge.m
2: %%%%Main程序%%%%%%
3: %%%%%%
4: %%%%%%本程序合并完各个子文件夹中的txt到主文件目录下,并且合并的文件以子文件夹名字命名
5: %%%%%%同时,每次合并时,如果主文件夹已存在某一个子文件夹名字A的txt文件,那么此次合并,将把当前
6: %%%%%%这个子文件夹A中所有的txt文件追加到子文件夹A.txt文件的末尾处。
7: clear;
8: clc;
9: % MainFolder='D:\Master-FTP\磁流变阻尼器实验\'; %%设置主目录,注意结尾要有个'\'
10: MainFolder='E:\txt文件夹\';
11: dirOutput=dir(fullfile(MainFolder)); %%获取主目录下所有文件夹与文件
12:
13: num=size(dirOutput);%%获取数量
14: for i=1:num(1)
15: if dirOutput(i,1).isdir == 1 %判断是否为文件夹
16: a1=~ strcmp(dirOutput(i,1).name,'.'); %%排除'.'和'..'的文件夹
17: a2=~ strcmp(dirOutput(i,1).name,'..');
18: if a1 && a2;
19: dirOutput(i,1).name;
20: y=TAllFileInAFolder(MainFolder,dirOutput(i,1).name);
21: end
22: end
23: end
24: disp('合并完成');
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
1: %% TAllFileInAFolder.m
2: function yyy=TAllFileInAFolder(MainFolderName,SubFolderName) %%合并子文件夹下所有txt,存到主文件夹下,以子文件夹命名
3: fileFolder=fullfile(MainFolderName,SubFolderName);
4: dirOutput=dir(fullfile(fileFolder,'*.txt'));
5: fileNames={dirOutput.name}';
6: num=size(dirOutput);
7:
8: file2=strcat(fileFolder,'\..\',SubFolderName,'.txt');%%保存路径
9: fid2=fopen(file2,'a');
10: for i=1:num(1)
11: file1=strcat(fileFolder,'\',fileNames{i,1});%%读取的文件
12: fid=fopen(file1,'r');
13: %txt=fscanf(fid,'%s');
14: txt=fread(fid,inf);
15: fclose(fid);
16: %fprintf(fid2,'%s',txt);
17: fwrite(fid2,txt);
18: %fprintf(fid2,'\r\n')表示在写完每个txt文件之后,写入一个回车换行符,得到下一个txt从新的一行开始写
19: fprintf(fid2,'\r\n');
20: end
21: fclose(fid2);
22: yyy=1;
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
主文件夹下的子文件夹:
某一子文件夹下的txt数据文件:
执行合并之后:
多次执行合并之后从文件大小可知其是子文件夹中txt数据是追加到已合并的子文件夹.txt中的。
<本文实现源码参考源>http://wheartbeating.blog.163.com/blog/static/2044620422013102811336829/
matlab批量合并txt文件的更多相关文章
- matlab批量读取一个文件夹里类似命名的mat文件
参考网址: Matlab读取同一路径下多个txt或mat文件总结 matlab 批量读取数据文件.mat .dat 整理:matlab批量读入数据文件的方法 首先命名方式体现在只是名字里数字有变化,其 ...
- 使用ffmpeg批量合并flv文件
title: 使用ffmpeg批量合并flv文件 toc: false date: 2018-10-14 16:08:19 categories: methods tags: ffmpeg flv 使 ...
- R语言笔记004——R批量读取txt文件
R批量读取txt文件 本文数据,代码都是参考的是大音如霜公众号,只是自己跟着做了一遍. path<-'C:\\Users\\Administrator\\Desktop\\docs' docs& ...
- python批量创建txt文件,以demo.txt内的内容为文件名
#批量创建txt文件import sys,osa=open("demo.txt")n=0aList=[]for line in a.readlines(): aList.appen ...
- matlab之导入txt文件并取其中一列数据
1.我想导入下面这个文件的内容,并且获取这个文件中的两列数据. 2.首先确保Matlab当前所在文件夹为txt文件所在文件夹,然后命令行执行: X = load('2019_03_21_08_59_0 ...
- MATLAB:读取txt文件中物体的三维坐标,显示三维模型
在MATLAB中建立一个脚本show3Dtxt.m文件,编写代码: clear; %%read 3D data fileID= fopen('E:\博士\深度学习与三维重建\代码实现\voxel_gr ...
- python批量读取txt文件为DataFrame
我们有时候会批量处理同一个文件夹下的文件,并且希望读取到一个文件里面便于我们计算操作.比方我有下图一系列的txt文件,我该如何把它们写入一个txt文件中并且读取为DataFrame格式呢? 首先我们要 ...
- 使用Python批量合并PDF文件(带书签功能)
网上找了几个合并pdf的软件,发现不是很好用,一般都没有添加书签的功能. 又去找了下python合并pdf的脚本,发现也没有添加书签的功能的. 于是自己动手编写了一个小工具,使用了PyPDF2. 下面 ...
- MATLAB的SAVE命令动态批量保存TXT文件
1.使用save(): for i=1:6 str=[num2str(i),’.txt’]; m=[1 2; 3 4]; save(str,’m’,’-ascii’);%注意m的单引号,一定记得加上, ...
随机推荐
- gradle研究
gradle介绍:http://www.oschina.net/p/gradle gradle官网:https://gradle.org gradle的 eclipse 插件:http://www. ...
- Saiku 下载,安装
Saiku是一个模块化的开源分析套件,它提供轻量级的OLAP(联机分析处理),并且可嵌入.可扩展.可配置. 主页:http://community.meteorite.bi 如何安装摘自: http: ...
- ReportViewer技巧汇总
在MVC项目中使用ReportViewer 创建WebForm,向Webform中添加ReportViewer控件,通过CodeBehind设置报表参数并填充数据,测试通过后在MVC的View中iFr ...
- Effective Java 72 Don't depend on the thread scheduler
Principle Any program that relies on the thread scheduler for correctness or performance is likely t ...
- Javascript中substr和substring的区别
由于在项目中有需要对字符串进行截取,然后手残使用了IDE自动提示的substr,没想那么多以为substr和substring没多大区别. 然而并不是,且听我一一道来. 1. substr(index ...
- NSThread基础使用
1.创建和启动线程 一个NSThread对象就代表一条线程; 创建,启动线程 NSThread *thread = [[NSThread alloc] initWithTarget:self ...
- OpenStack overview 笔记
Example architecture example architecture 至少需要两个节点启动一个虚拟机或者实例.可选的服务,例如Block storage和Object storage需要 ...
- [转载]ExtJs4 笔记(7) Ext.tip.ToolTip 提示
作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...
- hdu-4811 Ball
题目链接: Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- UESTC 424 AreYouBusy --混合背包
混合三种背包问题. 定义:dp[i][k]表示体积为k的时候,在前i堆里拿到的最大价值. 第一类,至少选一项,dp初值全赋为负无穷,这样才能保证不会出现都不选的情况.dp[i][k] = max(dp ...