How to Link Script Files in MATLAB

104 10

    Add Scripts to MATLAB's Search Path

    • 1). From within MATLAB, click on the File menu, then click on "Set Path..." A window will appear, showing a long list of folders under the label "MATLAB search path:".

    • 2). Click the "Add Folder..." button. A window will appear allowing you to navigate the files and folders of your computer.

    • 3). Navigate to the folder containing the script or scripts you would like to link. Then click "Open." You should see the folder you chose appear at the top of the "MATLAB search path" list.

    • 4). If you have other scripts in different folders, click "Add Folder..." again, navigate to one of the other folders, and then click "Open." Repeat until all the folders containing your scripts are shown in the "MATLAB search path" list.

    • 5). Click the "Save" button below the "MATLAB search path" list. This tells MATLAB that when you invoke a script by name. MATLAB should look in each folder in that list until it finds a script with that name.

    Invoke One Script from Another

    • 1). Click on the "File" menu, then click "Open..." and choose the script file from which you want to invoke another script.

    • 2). Edit the script file by typing the name of the script you want to invoke. For example, you are editing a file named script1.m, and you want to call a file named script2.m from within script1.m. In script1.m, at the point where you want to call script2.m, type "script2" without the quotation marks, on a line by itself -- do not type "script2.m." Since you added the folders containing script1 and script2 to the MATLAB search path, it does not matter if they are in the same folder or not. Save script1.m by clicking "File" and "Save."

    • 3). Type the name of the first script at the MATLAB command line. Using the example, you would type "script1." MATLAB will now run script1, which will in turn run script2.

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.