uiget files of multiple formats matlab in matlab

You can use the uigetfile function in matlab to open a dialog box and select multiple files of different formats.

Here's an example code snippet:

main.m
[filename, filepath] = uigetfile({'*.mat';'*.txt';'*.csv';'*.xlsx';'*.jpg';'*.png'},'Select Files','MultiSelect','on');

if isequal(filename,0) || isequal(filepath,0) % user clicked cancel
    disp('User selected Cancel')
else
    if iscell(filename) % multiple files selected
        for i=1:length(filename)
            disp(['User selected ', fullfile(filepath, filename{i})])
            % process the selected file here
        end
    else % single file selected
        disp(['User selected ', fullfile(filepath, filename)])
        % process the selected file here
    end
end
585 chars
16 lines

Here we are using the uigetfile function to open a dialog box with file filter types (in this case, .mat, .txt, .csv, .xlsx, .jpg and .png). The user can then select one or multiple files of these formats, which returns a filename and filepath cell arrays respectively.

We use a conditional statement to check if the user clicked cancel or actually selected a file. If the user selected a file, we process each selected file using a for loop (if multiple files are selected) or directly (if a single file is selected).

related categories

gistlibby LogSnag