涉及到内容:
1.获取文件名称,并根据名称与名单进行比对
2.拷贝文件
% filename is deliverdata clc;clear all;close all; %读取文件名 fileFolder=fullfile('D:\z'); dirOutput=dir(fullfile(fileFolder,'*.nii')); fileNames={dirOutput.name}'; tmp1=size(fileNames); lenth=tmp1(1,1); %读取被试编号 textNum=textread('613Big497.txt','%s');%n*1 %切割名字 BrianNumCell={}; for n=1:lenth tmpName=fileNames{n,1}; cell2part=strsplit(tmpName,{'_SUB','_'});%1*5/6 cell 数字在1.2 m=size(cell2part); lenth2=m(1,2);%number nameNum=cell2part(1,2);%1*1cell log=ismember(nameNum,textNum); pice1='_SUB'; pice2='_'; if log==1 a=cell2part{1,1}; Name1=sprintf('%s%s',a,pice1); b=cell2part{1,2}; nameText=cell2part{1,2}; Name2=sprintf('%s%s',Name1,nameText); Name3=Name2; for s=3:lenth2 tmpc=cell2part{1,s}; cPlus=sprintf('%s%s',pice2,tmpc); Name3=sprintf('%s%s',Name3,cPlus);%得到完整的文件名 end BrianNumCell{n,1}=Name3;%得到名单 else end BrianNumCell(~any(cellfun(@nnz,BrianNumCell),2),:)=[]; end %复制文件 SOURCE_PATH_t = 'D:\z\';%源文件目录 DST_PATH_t = 'D:\Gene-Guts-Behavioral-Brain Research Project to Chinese Personality\Data Analysis\6.13-VMHC-497\';%目的文件目录 total=size(BrianNumCell); lenth3=total(1,1); for g=1:lenth3 dataname=BrianNumCell{g,1}; datasorce=[SOURCE_PATH_t,dataname]; copyfile(datasorce,DST_PATH_t); end
标签:02,文件,end,名单,cell2part,sprintf,PATH,BrianNumCell,Name3 From: https://www.cnblogs.com/MJnotes/p/16757808.html