您的位置:首页 > 编程语言 > MATLAB

matlab中文件的复制

2015-09-18 11:21 288 查看
下面这个程序完成的功能就是根据聚类之后的结果,把相对应的波形csd文件拷贝到相应的类别中。

clc;
clear;
NODE='OUTPUT1';
path_fault='G:\wuproject\wu123\CSDF_Files\fault\';//源文件地址
path_cluster='G:\matlab_work\二分K均值聚类bywu注释\';//目的地址
 load('G:\wuproject\wu123\Cluster_result\OUTPUT\OUTPUT_cluster.mat')//OUTPUT_cluster.mat中保存着聚类后的结果
if path_fault(end)~='\'
     path_fault=[path_fault,'\'];
end
if path_cluster(end)~='\'
     path_cluster=[path_cluster,'\'];
end
[cluster_list_row  cluster_list_col]=size(cluster_list);
%将cluster_list中的每个类中对应的fault波形保存在指定的路径下
DIRS=dir([path_fault,'*.csd']);  %扩展名
n=length(DIRS);
for k=1:cluster_list_col
    for i_csd_num=1:n %把每个csd文件的序号提取出来,看每个类中是否包含此序号,若包含有,则进行拷贝       
        if  find(cluster_list{1,k}{1,2}==i_csd_num)>0
            path_dist=[path_cluster,NODE,'\cluster-',num2str(k),'\'];
            path_source=[path_fault,DIRS( i_csd_num).name];
            if  ~isdir(path_dist)
                   mkdir(path_dist);
            end
            copyfile(path_source,path_dist);
        end
    end
end


上面是自己在项目中遇到的一个实际的例子,关于文件的复制。下面就将matlab文件的复制这个功能从项目中提取出来,并举一个例子来进行讲解。

文件的复制的知识点就是

copyfile(path_source,path_dist);


例子代码如下

function copy
% 从father目录中复制指定类型的文件到目录s中
father='H:\前期测试\3\'; %指定类型的文件所在的目录
s='H:\前期测试\3.3\'; %复制文件的目标目录
subDir=dir(father); %求目录的子目录
len = length(subDir); %求子目录的长度
disp('begin copy files..');
for i=3:len
    imgNames = dir(strcat(father,subDir(i).name,'\','*.JPEG'));
    a=[s,subDir(i).name,'\'];
    mkdir([s,subDir(i).name])
    for j=1:20 %复制的文件个数
        copyfile([father,subDir(i).name,'\',imgNames(j).name],a);
    end
end
disp('end');
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: