% ECE 1250 S12 Lecture 5 %------------------------------------------------------------------------------- % Advanced Indexing, finish remaining topics. (See handout on website.) %------------------------------------------------------------------------------- %------------------------------------------------------------------------------- % Writing script files. %------------------------------------------------------------------------------- % Change directory to where script files are located so Matlab¨ can find them, % or use the Set Path command under the File menu to add the folder with % the script files to where Matlab¨ looks for commands. % Use .m extension on file name. Put in commands just as you would at the % >> prompt in the command window. Here's a simple example of a script file % we shall call my_magic.m % my_magic.m Script to print a 3 x 3 magic square. A = magic(3) display('That''s a magic square!') return % To execute the script file my_magic.m, type the filename without the .m >> my_magic A = 8 1 6 3 5 7 4 9 2 That's a magic square! % Be careful not to create files with the same name as a Matlab¨ command. % For example, say you create a file called plot.m. When you use the plot % command, Matlab¨ will execute the first plot.m file it finds in the % search path. If your plot.m was found first, you would no longer have % access to Matlab¨'s plot command. % How to get rid of your plot.m command once it gets into Matlab¨ (and gets % compiled and stored in memory so the file is no longer accessed directly)? % 1) Remove or rename your file. % 2) Use the clear command to clear the filename, e.g., >> clear plot % The next time you type "plot", Matlab¨ will go through the search path % again and find the correct file. % Example script file to analyze students' test scores: see my_script.m