exporting-​to-excel-s​preadsheet​s

21 views (last 30 days)
my8950
my8950 on 24 Apr 2025
Commented: my8950 on 30 Apr 2025
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!

Accepted Answer

Cris LaPierre
Cris LaPierre on 24 Apr 2025
Edited: Cris LaPierre on 28 Apr 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.
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 Comments
Cris LaPierre
Cris LaPierre on 30 Apr 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.
my8950
my8950 on 30 Apr 2025
I'll check it out and see what I can find, thank you for this info!

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 24 Apr 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.

my8950
my8950 on 28 Apr 2025
Thank you both for responding. I will have to take a hard look at these to try and get a better understanding. If there is a way to, I could probably post a sample for reviewing. I really need to figure this out though, as mentioned, I think it could be modified a touch and used across multiple file types which would make things much faster for processing.
  2 Comments
Cris LaPierre
Cris LaPierre on 28 Apr 2025
Use the paperclip icon to attach your file to your post.
my8950
my8950 on 28 Apr 2025
Moved: Cris LaPierre on 28 Apr 2025
@Cris LaPierre, found it, thank you!
Attached is an abbreviated sample file for reference. Example, I'd want to pull 3 names from Row1, RPM, Batt_Voltage and Water_Temp. Out of those, I'd want to find say, min, max and average. I'd have something like, "X"_Min, "X"_Max, "X"_Average to take from the data file and move to a seperate file, so that once I go through all of the data files to process, I could just look at my output file after MatLab processed and see the Filename, Min's, Max's, and Averages for each data file.
It seems so basic to do, but actually getting where I want to be is a little overwhelming. Thanks everyone for your help!

Sign in to comment.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!