Posts

Showing posts with the label MATLAB

3. Using Files

PROFESSOR: This is Dr. MATLAB, lecture 3. If you're using MATLAB on the command line for enough time, you realize that you really want to save a bunch of commands in a file and then execute all those commands in one go. This helps you so that if you have typos, you can correct the typos without introducing new ones. It also allows you to create large pieces of code that call each other and really have complicated projects. To see how this works, we need an example. What we'll do is generate the Fibonacci sequence. So in the Fibonacci sequence, the first two terms are 1. And then each term is the sum of the previous two, like that. Notice that this will create a new term in f that will be the sum of the very last one plus the second-to-last one. Here it created 2, the sum of 1 plus 1. If we run that command again, it will generate 3, and then 5, and then 8, and then 13, et cetera. So now I want to take these three important lines-- this one, this one, and this one-...