I am running some code that runs through a directory, takes data from the files, plots the required data form each, and then saves the figure into the same folder before moving onto the next file. The code and processes work fine with the correct data being taken, only when going to the directory where the figures were saved, their extension shows as some number 'file'. e.g. '2 file', '25 file' etc. I can open the fiigure file in paint, but would prefer the file to be saved as what I specified. Here is the code I'm using;
clear allclose allclcfiledirectory = 'C:\Users\Me\OneDrive\Documents\University\Rogue Waves\Part1\Initial Conditions\Practise\';filepattern = fullfile(filedirectory, '*.txt');files = dir(filepattern);for k = 1:length(files)filename = files(k).name;fullfilename = fullfile(filedirectory, filename);fprintf(1, 'Running simulation for %s\n', fullfilename);%process data ...
figure, pcolor(tt,xx,abs(u_arr))xlabel(['Time (s)']);ylabel('Evolution Lab Space (m)');title('Numerics')shading interp%title(['Nonlinear Time is ' num2str(T_NL,3) ' s, Soliton Period is ' num2str(pi/2*T_D,3) ' s' ])
colormap(jet)colorbarstr = strcat('Numerics', filename);savename = strrep(str,'.txt','');%save the figure in folder
saveas(gcf, fullfile(filedirectory, savename), 'png')close(gcf)end
Example of the file extension:
Best Answer