How to create a loop that will plot multiple excel files into seperate graphs

3 views (last 30 days)
Hi all,
I'm trying to plot a bunch of individuals graphs using individual excel sheets. I want to extract the same variables ( all of them are organized in the same way).
For this, I know I have to create a loop and add my plotting function within it but I am having a bit of trouble doing this.
I have a looping code here, but I'm not sure how to integrate the plotting function I need into.
My file names increment from 101trf.xlsx, 102trf.xlsx, 103trf.xlsx and so forth.
Here's the code I have for the loop:
myFolder= dir('D:\Thesis\Reports\Encoding\Encoding Trial Reports\Free viewing Reports\Run1');
filePattern = fullfile(myFolder, '.xlsx'); % Change to whatever pattern you need.
theFiles = dir('101trf','102trf','103trf','104trf','105trf','106trf','107trf','108trf','109trf','110trf','111trf','112trf','113trf');
for k = 1 : length(theFiles)
baseFileName = theFiles(k).xlsx;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
end
I want to extract the colomns with the name 'trialnum' and 'FIXATION_COUNT' within these files to create a bar plot for them.
Thanks in advance!

Answers (1)

darova
darova on 24 Sep 2019
Try this. Don't forget to change column range!
myFolder = 'D:\Thesis\Reports\Encoding\Encoding Trial Reports\Free viewing Reports\Run1';
filePattern = fullfile(myFolder, '.xlsx'); % Change to whatever pattern you need.
for k = 101 : 113
fullFileName = [myFOlder sprintf('%dtrf.xlsx',k)];
colA = xlsread(fullFileName,'A:A'); % what is you column?
colB = xlsread(fullFileName,'B:B');
figure
bar(colA,colB)
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!