How to get the file path inside a script, function, or model?
How can I get the path of the script or function being executed or model being run from inside the file itself?
ANSWER
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
For scripts and functions:
[filepath,~,~] = fileparts(mfilename('fullpath'))
or simply
filepath = fileparts(mfilename('fullpath'))
Note:
-This works with M file scripts and functions during normal execution.
-This will not produce the desired result for MLX live scripts or in “%%” sections of scripts run individually.
-The functions used are not supported for code generation.
For live scripts (or “%%” sections of scripts):
[filepath,~,~] = fileparts(which('your_file_name'))
or simply
filepath = fileparts(which('your_file_name'))
Note:
SEE COMPLETE ANSWER CLICK THE LINK