Syntax
xy=tryuigetfile(xy,[fselect])
Input Parameter
xy : | | numerical parameter, empty or existing filename |
fselect : | | such as '*.avi;*.m4v;*.mp4;*.mov;*.mpg'; default is *.* |
Output Parameter
xy : | | numerical parameter, empty or existing filename |
Examples
tryuigetfile(12)
tryuigetfile('')
tryuigetfile('notexistingfile.avi')
Copyright 2017-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This function, tryuigetfile
, is designed to handle file selection in MATLAB. It is particularly useful when numerical parameters are generated by analyzing a file. The function checks if the input is a valid file or directory, and if not, it prompts the user to select a file through a dialog box.
Input Parameters
- xy: This can be a numerical parameter, an empty value, or an existing filename. It is the primary input that the function evaluates.
- fselect: This is an optional parameter that specifies the file types to filter in the file selection dialog. It defaults to '*.*', meaning all files are shown. It can be set to specific file types like '*.avi;*.m4v;*.mp4;*.mov;*.mpg'.
Output Results
- xy: The output is either the original numerical parameter, an empty value, or a valid filename. If no file is selected, the result is empty.
Algorithm Steps
- Initialize
fselect
to '*.*'. If a second argument is provided and is not empty, update fselect
with this value.
- Check if
xy
is not numeric and if it is either empty or not an existing file or directory. This is done using the exist
function to verify the file or directory existence.
- If the conditions in step 2 are met, open a file selection dialog using
uigetfile
with the filter fselect
.
- Concatenate the selected path and filename into
xy
.
- If the length of
xy
is zero, set xy
to an empty array.
- Check if
xy
is not empty and if it does not exist as a file. If so, set xy
to an empty array.
Example Usage
tryuigetfile(12)
: Passes a numerical parameter, which is returned as is.
tryuigetfile('')
: Opens a file dialog since the input is empty.
tryuigetfile('notexistingfile.avi')
: Opens a file dialog since the file does not exist.
Algorithm explaination created using ChatGPT on 2025-08-19 07:15. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21