Problem Part 1

MATLAB

Use MATLAB help to find out how you can create a new directory named mynewdir from the MATLAB command line. Then change the working directory the newly-created directory. Then create a MATLAB script in this directory named myscript.m with the following code in it,

% First create an array from -2*pi to 2:pi
x = -2*pi:pi/20:2*pi;

% Calculate |sin(x)|
y = abs(sin(x));

plot(x,y);

Now on MATLAB command line, run the script by calling its name. What do you get? Save the output as a figure and submit it as part of your answer.

Problem Part 2

MATLAB

Now change your working directory to the original directory before you created mynewdir directory. Try to run the script myscript you had created again, from MATLAB command line. What do you get? and why?

Comments