How to process multiple sub - folders in main folder

10 views (last 30 days)
Hi,
I'm currently in the process of processing data from 5 files within a folder. I have 1 main folder containing 8 subfolders, each containing 5 files. Right now im already able process the files within 1 single sub-folder to how i want. However I want to be able to process the each individual subfolder(Data type analysised is same for all subfolders). Sub folders are called (70ml, 80ml....).
Code: (For 1 sub-folder)
cd 'C:\Hello\A.......\70ml'; (Main Folder called 'C:\Hello\A' containing 'C:\Hello\A.......\70ml', 'C:\Hello\A.......\80ml' etc)
files = dir('*r.png');
compiledArr = zeros(8,5)
for i = 1:size(files)
filename = string(files(i).name);
imread(filename);
SummaryPage = imread(filename);
J = imresize(SummaryPage, 4);
roi = [1589 528 1376 1368];
ocrResults = ocr(J, roi);
for LC = 1:8
wordCells = ocrResults.Words;
tempStr = wordCells(LC);
tempStr = strrep(tempStr,",","");
tempNum = str2double(tempStr)
valArr(LC, 1) = tempNum
end
switch i
case 1
compiledArr(:, i) = valArr
case 2
compiledArr(:, i) = valArr
case 3
compiledArr(:, i) = valArr
case 4
compiledArr(:, i) = valArr
case 5
compiledArr(:, i) = valArr
end
end
Do you have any suggestions on how this could be done? Thank you!

Answers (1)

Rashedur Rahman
Rashedur Rahman on 26 Mar 2020
Try this code please.
You should check the following link also
  1 Comment
Wen Jun Chua
Wen Jun Chua on 26 Mar 2020
Edited: Wen Jun Chua on 26 Mar 2020
Hi, i tried the code and repace with my own directories and such but i now have an error called
Index exceeds the number of array elements (1).
at this line tempStr = wordCells(LC);
Could it be because of i hardcoded at the switch part? any suggestion on improvement i can do

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!