Keeping Headers When Import Excel Then Running Code and Exporting
Mostrar comentarios más antiguos
I have a code which will scale the data I have from each excel files in a folder director. Then, after the data is scaled, the code allows for the creation of the scaled spreadsheets in a different outfile folder.
The problem I have is that I need the header information to transfer to the new created spreadsheets. This is important.
This is my code:
indir = 'C:\Users\Maki\Desktop\PoissonWeek\ForScale'; %path to input directory
outdir = 'Scaled'; %path to where to put the results
if ~exist(outdir, 'dir'); mkdir(outdir); end
dinfo = dir(fullfile(indir, '*.xlsx'));
filenames = {dinfo.name};
nfiles = length(filenames);
for K = 1 : nfiles
thisfile = filenames{K};
infile = fullfile(indir, thisfile);
outfile = fullfile(outdir, thisfile);
Z = readtable(infile)
A = Z{:,:}
X = std(A)
outdata = (A - mean(A)) ./ X
writematrix(outdata,outfile);
disp('An error occurred while retrieving information from the internet.');
disp('Execution will continue.');
end
To illustrate, I've attached a spreadsheet that would be an infile ("10001_infile.xlsx"). And, I've attached a sample spreadsheet of the processed outfile of that spreadsheet ("10001_outfile.xlsx")
On the infile, there are the following headers:
BackUp Break Catch Manhole PRCP Street
On the outfile, the first row begins with values. There are no headers
I need my code to run where the outfile includes headers, yet also ensures that the headers are matching the columns. Since not all spreadsheets will have 6 columns. Some have 5 columns.
Maybe there is an "if and" statement needed... I've been searching. I just can't find the right method.
I would appreciate any help with the this. Thank you.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Standard File Formats en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!