访问多个文件夹 matlab 并存储在同一个垫子中

Accessing multiple folder matlab and store in same mat

我是 Matlab 的新手。我有如下代码。如何读取多个文件夹。我知道通过使用循环,但不知何故我用谷歌搜索我找不到它。另外,我在下面写的是 myA 文件夹。如何为 myA、myB、myC 将 featureVector 放在同一个垫子 AllTrain 中?该文件夹包含图像。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
clear all;
clc;

trainlabel = [];
featureVector = [];
AllTrain = [];

% Specify the folder
myA = 'C:\\Users\
otComplex\\a';
myB = 'C:\\Users\
otComplex\\b';
myC = 'C:\\Users\
otComplex\\c';

for k = 1 : length(theFiles)
 baseFileName = theFiles(k).name;
 fullFileName = fullfile(myA, baseFileName);
 fprintf(1, 'Now reading %s\
', fullFileName);
 % Now imread the file
 imageArray = imread(fullFileName);
 imageEdge = edge(imageArray, 'canny', 0.4);

 a_inv_mom = Hu_Moments(imageEdge);
 format short
 a_inv_mom_normal = -sign(a_inv_mom).*(log10(abs(a_inv_mom)));

 featureVector = cat(1,a_inv_mom_normal);
 AllTrain(k,:) = [featureVector k];

 % imshow(imageEdge);  % Display image.
 drawnow % Force display to update immediately.
end


要紧凑:

1
2
3
4
5
6
folderCell = {'C:\\Users\
otComplex\\a', 'C:\\Users\
otComplex\\b', 'C:\\Users\
otComplex\\c'};

theFiles = cellfun(@(x) fullfile(x, '*.pgm'), folderCell, 'UniformOutput', false);

然后你可以继续你的循环,theFiles 将包含所有三个目录中的所有 .pgm 文件