MATLAB: Saving .pdf using your imported .csv file name

importing excel datasaving pdf

I have several .csv data files which are brought into Matlab. In a for loop, a bunch of calculations are made and then plotted on a graph. Each iteration needs a unique filename for the plot, but I'd like to have the same file name for the plot as the .csv. For example, I bring in Data2554.csv and Data2783.csv, I would like the plots to be Data2554.pdf and Data2783.pdf.
Does anyone know an easy way to do this?
files = dir('*.csv');
num_files = length(files);
for i = 1:num_files;
data{i} = xlsread(files(i).name);

Best Answer

[filedir, basename, ext] = fileparts(files(i).name);
pdfname = fullfile(filedir, [basename '.pdf']);