Validate that path refers to file
mustBeFile(path)
example
mustBeFile(path) throws an error if path does not refer to a file. This function does not return a value.
path
mustBeFile calls the following function to determine if the input is file:
mustBeFile
isfile
collapse all
Use the mustBeFile function to ensure that a file path passed to a function is valid.
The readLine function ensures that the file path is valid before accessing the file.
readLine
function r = readLine(path) arguments path {mustBeFile} end fid = fopen(path); r = fgetl(fid); fclose(fid) end
Passing this path to a folder to the readLine function results in an error.
r = readLine("C:\Users\Public")
Error using readLine Invalid argument at position 1. The following files do not exist: 'C:\Users\Public'.
Path to a file, specified as the fully qualified file name, including folders containing the file from the context in which the function executes.
Example: "H:\myfolder\myfile.txt"
"H:\myfolder\myfile.txt"
Data Types: char | string
char
string
mustBeFile is designed to be used for property and function argument validation.
arguments | mustBeFolder
arguments
mustBeFolder