How to process multiple sub - folders in main folder

4 次查看(过去 30 天)
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!

回答(1 个)

Rashedur Rahman
Rashedur Rahman 2020-3-26
Try this code please.
You should check the following link also
  1 个评论
Wen Jun Chua
Wen Jun Chua 2020-3-26
编辑:Wen Jun Chua 2020-3-26
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by