Group_Test1 is empty

1 view (last 30 days)
sun rise
sun rise on 31 May 2021
Answered: Star Strider on 31 May 2021
It does not enter the for j loop, so Group_Test1 is empty
clear all
clc
sad = dir('D:\Project\DB1\test\'); % Returns both folders and files
% sad = dir(pwd); % Returns both folders and files
cell_array_of_folder_names = setdiff({sad([sad.isdir]).name},{'..','.'}); % Select folder names
% cell_array_of_folder_names( strncmp( cell_array_of_folder_names, ".", 1 ) ) = []; % Remove '.' and '..'
sorted_cell_array_of_folder_names = sort_nat( cell_array_of_folder_names );
% sorted_cell_array_of_folder_names = cell_array_of_folder_names; % if you don't have sort_nat
whos sorted_cell_array_of_folder_names
%----------------
[mp1, np] = size(sorted_cell_array_of_folder_names); % compute size = number of subfolders & files & . & ..
csf1=0; % counter of JUST subfolders found in PF
t=1;
Group_Test1 = zeros(1, mp1);
for i=1:np
% Keep only folders:
csf1 = csf1 +1; % one sub folder found
SFN = sorted_cell_array_of_folder_names{i};% extract his name
tifList = ls(fullfile('%s%s%s%s',SFN,'\','*.tif')); % list all jpg files
[ms1, ns] = size(tifList); % ms = number of image files found
% Processing for each tif file:
for j=1:ms1
tifFileName = tifList(j,:); % extract name of tif file
% IM=imread([PF SFN '\' tifFileName]);
%t=1;
%for i=1:csf1
% for j=1:ms1
Group_Test1(t)={i};
t=t+1;
end
%PF_SFN_imgName = FULLFILE('%s%s%s',SFN,'\',tifFileName);
Group_Test1 = Group_Test1(1:t-1); % Crop off any unused elements
end
%Group_Test1 = Group_Test1(1:t-1); % Crop off any unused elements
save('Group_Test','Group_Test1');
%----------------------
I want to order each folder separately and give all the pictures in it the same name or label
First the folders are arranged, then all the pictures inside the folder are named with the same name. For example: The pictures in Volume 1 are all named with Name 1 ... and so on ...

Answers (1)

Star Strider
Star Strider on 31 May 2021
If ‘np’ is 0 (the cell array is empty), the loop is satisfied at the outset and never iterates. If ‘np’ is 1, the loop iterates one time, then stops.
Determine what ‘np’ is in order to solve this. Fixing that problem may be more involved.
.

Categories

Find more on Linear and Nonlinear Regression 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!