exporting-to-excel-spreadsheets
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am trying to do what I feel is very basic task. I have numerous excel files. Parameter name across the top row, data point from row 2:xxxx.
What I want to be able to do is go through a number of files, grab the filenames, column x name for title, and say search for the highest poinit in that column, or calculate average of that column.
I'm struggling to really understand how to do this, I'm no programmer, that is 100% certain. If I could get something put together to do this I feel that it could help to me process a majority of the files I work with, not doing this exact task, but very similar. I've not had the best of luck finding responses by searching forums, etc to do this for people who don't understand programming, so I'm looking for an idiots guide to how to do basic tasks like this with matlab. If anyone has something they think would help, please post up.
Thanks!
0 commentaires
Réponse acceptée
Cris LaPierre
le 24 Avr 2025
Modifié(e) : Cris LaPierre
le 28 Avr 2025
You will need to load each file into MATLAB in order to process the data. There are various techniques depending on how your data is organized.
I'd start with the answer recommended in this answer: https://www.mathworks.com/matlabcentral/answers/473494-using-readtable-to-load-excel-files-in-a-different-folder
folder_in='Formatted_Excel'; % directory of interest
d=dir(fullfile(folder_in,'*.xls*')); % return the .xls files in the given folder
for i=1:numel(d)
P=readtable(fullfile(folder_in,d(i).name));
...
% do whatever w/ the i-th file here before going on to the next...
...
end
9 commentaires
Cris LaPierre
le 30 Avr 2025
We share an example of this type of workflow in this video from the Data Processing with MATLAB specialization on Coursera. You can enroll for free, and might find the rest of the content helpful as you try to learn MATLAB.
Plus de réponses (2)
Walter Roberson
le 24 Avr 2025
datadir = '.'; %path to data files
dinfo = dir(fullfile(datadir, '*.xslx'));
filenames = fullfile({dinfo.folder}, {dinfo.names});
numfiles = numel(filenames);
results = table('Size', [numfiles, 4], 'VariableTypes', ["cell", "cell", "cell" "cell"], 'VariableNames', ["varnames", "maxval","maxidx","avg"]);
for K = 1 : numfiles
thisfile = filenames{K};
T = readtable(thisfile);
data = T{:,:};
[maxval, maxidx] = max(data);
avg = mean(data,1);
results.varnames = T.Properties.VariableNames;
results.maxval(K) = {maxval};
results.maxidx(K) = {maxidx};
results.avg(K) = {avg};
end
This code does not assume that each file has the same number of columns or that the columns are in the same order.
This code does assume that the tables contain only numeric data.
This code does not assume that there is only one data column.
If I have coded correctly, then the end result should be a table with one row per file. The table should have four variables, "varnames", "maxval", "maxidx", and "avg". The entries in "varnames" should be the colum names for each file. The entries in maxval should be the maximum value for each row; the entries in maxidx should be the row index that the maximum value occurred; the entries in "avg" should be the average of each column.
The code would be more simple if it could be assumed that there is only one variable in each file and the one variable is always the same variable -- or if the it could be assumed that only one particular variable name is to be extracted from each file.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!