0

I have a folder which includes 1000 pcd files (a1,...,a1000). I want to read them in a loop in matlab and store each of them in a separate matrix (mat1,...,mat1000).

for example (as a pseudo code)

for i=1:1000
 mati = read(pcd(ai))
end

How can I do that?

shirin
  • 175
  • 2
  • 14
  • 1
    The specific function used for reading the files depends on the file format (I don't know the PCD format, sorry). As for creating those 1000 variables, that's usually a bad idea; [here's why](https://stackoverflow.com/a/32467170/2586922). It's much better to use a multidimensional array or cell array, so that instead of `mat234` you use something like `mat(:,:,234)` or `mat{234}` – Luis Mendo Jun 25 '20 at 20:34

1 Answers1

2

This can be useful: https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

You can loop through all the files with a specific extension in a folder using this code:

myFolder = 'C:\Users\...'; %The path to the folder which contains the files
filePattern = fullfile(myFolder, '*.pcd'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
    baseFileName = theFiles(k).name;
    fullFileName = fullfile(theFiles(k).folder, baseFileName);
    % Now do whatever you want with this file name
    % A{k} = pcread(fullFileName)
end

To store each of them in a separate matrix, you can use cell array.

Yahia Nagib
  • 91
  • 1
  • 3