How to get the file path inside a script, function, or model?

Technical Source
1 min readSep 30, 2021

--

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

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet