- #1
JeroenS
- 5
- 0
for a project i have to open, edit and save a varying amount of files. I use a MATLAB code for this. It works fine and imports all the .sp files in the directory with the fopen() command. The only problem i still have is that i also want to change the extension of the files. Right now i use dlmwrite inside a loop that that saves each and every file:
dlmwrite(files(j).name,x,'newline', 'pc','delimiter','\t')
In that case it perfectly saves all the editted files with the same name but also the same extension! I tried to use the 'save' command and that works but in that case its the other way around and the extension is changed but the filename is fixed so that it overwrites. Is there a way to save a matrix to a file with varying filename AND extension inside a loop?
Here is the crucial part of the code i have:
files = dir('Input\*.sp');
total=length(files);
for j=1:length(files)
cd('Input')
fid = fopen(files(j).name, 'r');
grades = textscan(fid, '%f %f %f', n, 'headerlines', h);
fclose(fid);
x=[grades{1,1} grades{1,2}];
x=sortrows(x,c);
for z=1:length(x)
x(z,2)=10^-x(z,2);
end
cd ..
cd('Converted files')
dlmwrite(files(j).name,x,'newline', 'pc','delimiter','\t') %write file
cd ..
end
dlmwrite(files(j).name,x,'newline', 'pc','delimiter','\t')
In that case it perfectly saves all the editted files with the same name but also the same extension! I tried to use the 'save' command and that works but in that case its the other way around and the extension is changed but the filename is fixed so that it overwrites. Is there a way to save a matrix to a file with varying filename AND extension inside a loop?
Here is the crucial part of the code i have:
files = dir('Input\*.sp');
total=length(files);
for j=1:length(files)
cd('Input')
fid = fopen(files(j).name, 'r');
grades = textscan(fid, '%f %f %f', n, 'headerlines', h);
fclose(fid);
x=[grades{1,1} grades{1,2}];
x=sortrows(x,c);
for z=1:length(x)
x(z,2)=10^-x(z,2);
end
cd ..
cd('Converted files')
dlmwrite(files(j).name,x,'newline', 'pc','delimiter','\t') %write file
cd ..
end