Hi! I have a question about how can I save a loop outputs. I want to write the output values of a large series of files on a separate line on text.txt. The problem is it only works with the first one, but it doesn't work with the rest. Is there something wrong?
myPath = 'C:\EX\'; a= dir (fullfile(myPath,'*.DIM')); fileNames = { a.name };% Rename files
for k = 1:length(fileNames) newFileName = [fileNames{k}(1:2) fileNames{k}(4:6) '.txt']; movefile([myPath fileNames{k}], [myPath newFileName]);end filePattern=fullfile( myPath,'*.txt'); txtFiles= dir(filePattern); for k = 1:length(txtFiles) baseFileName=txtFiles(k).name; fullFileName= fullfile(myPath,baseFileName); fid=fopen(fullFileName, 'r'); for i = 1:18 m{i} = fgetl(fid); end result2 = m{18}; result2b= result2([12:19]); fid=fopen(fullFileName, 'r'); for i = 1:30 m{i} = fgetl(fid); end result3 = m{30}; result3b= result3([12:19]); fid=fopen(fullFileName, 'r'); for i = 1:31 m{i} = fgetl(fid); end result4 = m{31}; result4b= result4([12:20]); fid=fopen(fullFileName, 'r'); for i = 1:19 m{i} = fgetl(fid); end result5 = m{19}; result5b= result5([12:20]); text= {baseFileName, result2b, result3b, result4b, result5b}; final= [Fields'; text]; end
I've read about fprint command and I've tried but it doesn't work at all. Really thanks in advance!
EDIT:
I added a screenshoot about my variables. Is it possible because of the txtFiles is wrong?
Best Answer