Save each result in different folders
Show older comments
Hi I have 259 text file in a folder,P(1).txt:P(529).txt, and wanna change all their names to just P and save each one of then in a folder by their numbers, I could do it for one of them but when I got the code to for loop I got this error: ??? Error using ==> fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> Untitled at 10
fprintf(fid2,'%s\n', str2{:});
any help will?
clc
clear
for i=2:530
fid1 = fopen(['P(' num2str(i-1) ').txt'],'r');
str1 = textscan(fid1,'%s','Delimiter','\n');
fclose(fid1);
OO=i-1
str2 = [str1{1}];
fid2 = fopen('E:\matlab\all\New folder\New folder (5)\VV\OO\P.txt','w');
fprintf(fid2,'%s\n', str2{:});
fclose(fid2);
end
Accepted Answer
More Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!