MATLAB: How to delete text files except one. deletetext file In one folder there are so many text files. I want to delete all that files except one named XYZ.txt using matlab. delete(*.txt) This function deletes all. So, how to do.? Best Answer yourfolder='d:/test/';f=dir([yourfolder '*.txt'])f={f.name}n=find(strcmp(f,'file.txt'));f{n}=[]for k=1:numel(f); delete([yourfolder f{k}])end Related SolutionsMATLAB: Read multiple text files as separate matrices The textscan function requires either an fid as input, or a character array. Your code doesn't actually read the data from the file, but from the file name.It will also overwrite the variable data every file. MATLAB: How to take the matrices stored in a loop one by one. Rather than doing this in loops, try this:D = 20;M = 100;K = 40;D_l = 0.3;tita_d = randn(D,1,K);A_k = bsxfun(@times, 0:M-1, sin(tita_d));A_k = exp(j*2*pi * D_l * A_k) / sqrt(D);It produces exactly the same output using vectorized code. You can reshape the output to be a matrix using this code:B_k = reshape(A_k,D,[]); Related QuestionOverwriting the folder in matlabHow to delete a particular row in multiple TXT filesIssue with data format when using textscan()How to detect folder address
Best Answer