Using a for loop to put a number of 2D arrays in a directory into a single 3D array
17 views (last 30 days)
I have a number of 2D arrays (image files) in a directory which I am trying to open sequentially in a for loop so I can window them down, and then put them all into a 3D array. I know this is a simple question, I' having trouble creating the 3D array while opening each 2D array in the for loop. So for instance If I have 3 arrays each 512 x 512 in a directory I just want to loop through all three files and make a 512 x 512 x 3 array.
for f_index = 1 :(total_files)
%get the name of the file
name_string = strcat(datapath,dirout(f_index + 2).name);
%read the data in
%concatenate each frame with the last
results = cat(3,data_frame(:));
I realize this is a beginners question. Thanks.
Arash Rabbani on 12 Nov 2019
If your images are PNG and located in a folder, just run this code on that folder. 'A' is the resulted matrice:
if ndims(IMG)>=3; IMG=rgb2gray(IMG); end