matlab中文件的复制

来源:互联网 发布:爱奇艺自制网络剧 编辑:程序博客网 时间:2024/06/07 12:41

下面这个程序完成的功能就是根据聚类之后的结果,把相对应的波形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,'\'];endif 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    endend

上面是自己在项目中遇到的一个实际的例子,关于文件的复制。下面就将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);    endenddisp('end');end
0 0
原创粉丝点击