I am attempting (poorly) to write an app in MATLAB app designer that can read in several folders containing a variable number of text files.
I stumbled upon uipickfiles and was wondering if anyone has any experience using it? Currently my app has a ButtonPushed callback that calls uipickfiles which then allows the user to choose the folders they wish to use. However, when I look at what is returned it is e.g. - if only one folder is selected - a 1x1 cell containing the path to the folder.
I am wondering if it is possible to manipulate this to create a callback that also reads the contents of all the textfiles in the folder and stores it as a mxn table or matrix?
I've tried using different variations of readtable or readmatrix on a folder with even one file in it to no avail. I keep getting an error - "filename" must be a string scalar or character vector. But I don't know how to make the app do what I want.
Any help at all would be greatly appreciated
uipickfile
will only do part of this for you. It will return the folders that you've selected (not their contents).
You can add some additional code to get the folder contents using wildcard matching to just get txt files for example
folders = uipickfiles('num',[]); %Get an unlimited number of folder selections
filter = '\*.slx';
file_contents = struct;
for i=1:length(folders)
current_folder = folders{i};
text_files_contained = dir([current_folder filter]);
file_contents(i).folder_path = current_folder;
file_contents(i).files = {text_files_contained.name};
end