MATLAB: Listing mat files in a directory and checking to see if they have a particular file.

listbox

Greetings I have been having a tough time creating a list of files (.mat files) in a directory in a listbox, and then checking to see if they contain a certain variable. I tried using uigetfile() but that hasn't panned out very well.
How do I get a list of files in a directory no matter what type they are and run a test on them to see if they contain a certain variable?
Thank you
Bill

Best Answer

Files=dir(fullfile('MyFolder','*.mat')) will give you a list of .mat files.
Files=dir(fullfile('MyFolder','*.*')) will give you a list of all files and subfolders.
Files is a structure array, check its fieldnames.
Vars=load('MyData.mat') will return Vars as a structure. fieldnames(Vars) gives you all the variable names in the .mat file.