1.8. Use the MATLAB Help Browser to find out how to create a new directory from
ID: 3751951 • Letter: 1
Question
1.8. Use the MATLAB Help Browser to find out how to create a new directory from within MATLAB. Then, create a new directory called mynewdir under the current directory. Add the new directory to the top of MATLAB’s path.
1.9. Change the current directory to mynewdir. Then open an Edit Window and add the following lines:
plot(t, x);
Save the file with the name test2.m and execute it by typing test2 in the Command Window. What happens?
1.10. Close the Figure Window and change back to the original directory that MATLAB started up in. Next type “test2” in the Command Window. What happens, and why?
I dont know how to go back to the original directory. I do cd .. and the program still opens up.
Explanation / Answer
1.8
To create a directory from within MATLAB Command Line, we use the mkdir command. To create the directory mynewdir in the current directory we use the command
mkdir mynewdir
Now, we can add this directory to the top of the MATLAB Path
-----
1.9
After saving the given program as test2.m , you then run it and it definitely runs fine as expected.
-----
1.10
Even after you change the directory using cd.. the code still works when you run it from the command line. This is so because you have added the directory mynewdirwhich contains test2.m at the top of the MATLAB Path. Whenever you want to execute a script in MATLAB, first it checks the current directory. If it doesn't find that script in the current directory then it searches through all the folders in the MATLAB Path in the order that you have defined where the top most folder is searched first. Since you had added mynewdir to the top of the MATLAB Path, after not finding test2.min the current directory, it then proceeds to search for it in the directory mynewdir where it does indeed find it and then runs it.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.