Create cell array of files from subfolder
Afficher commentaires plus anciens
I have a folder with 2 subfolders.
Each subfolder has a variable amount of text files, all containging unique data, in the same dimensions while having the same name.
E.g. Subfolder one = Temp.txt (500x14 table), Pressure.txt (400x10 table), Humidity (450x11 table)
Subfolder two = Temp.txt (500x14 table), Humidity (450x11 table)
I was using a fileDatastore to store these. How can I create a mulitlevel data store like this: fds.Files = 3x1 cell array, cell1 = Temp, cell2 = Pressure, cell3 = Humidity. Each cell being expandable, holding the tables containging the data? So the Temp array cell would be a 2x1 array containing a 500x14 table in cell1 and a 500x14 table in cell2?
I had written a code doing this and foolishly overwritten it this morning and now can't get it back. If there are any problems to this method please let me know. My code is below:
Dir = "C:\...";
Folders = dir(fullfile(Dir));
Folders = Folders(~ismember({Folders.name},{'.','..'}));
Folders = struct2cell(Folders);
Folders = transpose(Folders);
Folders = Folders(:,2);
Folders = unique(Folders);
fds = fileDatastore(Folders, ReadFcn=@(x) readtable(x,VariableNamingRule="preserve"), FileExtensions=".txt", IncludeSubfolders=true, ReadMode="file");
data = readall(fds);
[~,fileName] = fileparts(fds.Files);
Path_Name_Data = cat(2,Folder,fileName,data);
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!