MATLAB utilizes a path variable to access files needed by your scripts. Learn how to add files to the path.
- [Male Instructor] It's important to understand how MATLAB finds the scripts and functions that we write on the local computer. MATLAB uses what it calls the path to do this, and if we head up here into the toolbar, make sure we're on the Home tab, and you can click Set Path, and here we can see all of the folders that MATLAB will look in when it's trying to find functions or scripts. We see here at the top, we already have Documents MATLAB where we've been saving our current scripts, and then there's all the default tool boxes and things that MATLAB comes with.
So, for an example to see how the path works, let's say we have a script somewhere that isn't in the path. Here, I've got in our exercise files folder, another folder called SoManyPaths, and a file in there called Pathy, that just displays some text on the screen. If you go into our Command window, and type, "Pathy" MATLAB will throw us an error because it doesn't know where to find it. So, let's add that to our path and we'll click Set Path, add folder, and I'll go to the desktop.
Exercise files, and SoManyPaths. Let's select that folder. We can see that's now been added to the path, and don't forget you have to go down here and save. Now, when you click Save, MATLAB might tell you that you're unable to save the Path Def file, and that's just because you need administrator privileges, so you may need to restart MATLAB and run as administrator. I'm going to go ahead and click Save, and Close. Now, when we type "Pathy" MATLAB will look there first, and we see that "I love being in the MATLAB path." So, in the future, if you ever have trouble finding certain functions or scripts that you've written, make sure that they're added into the MATLAB path.
- Creating MATLAB variables
- Working with matrix and scalar operations
- Using if statements and loops
- Creating functions
- Importing data
- Building basic plots and 3D plots
- Working with images
- Creating Simulink models