How to create a loop that will plot multiple excel files into seperate graphs
조회 수: 14 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
darova
2019년 9월 24일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!