From the course: MATLAB 2018 Essential Training

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Perform operations multiple times using for loops

Perform operations multiple times using for loops - MATLAB Tutorial

From the course: MATLAB 2018 Essential Training

Start my 1-month free trial

Perform operations multiple times using for loops

- [Instructor] MATLAB works well with single numbers, but its real power comes from its ability to operate with entire vectors or matrices. In this movie, I will show you how to use for loops to move through all or part of a collection. I have a blank command window, but what I really need to do is create a script. So I will go over to the home tab, and click the new script button. Although I could've also pressed control N. And you just start by defining some variables to work with. So I'll start with a vector. I'll just call it vec1, and I will assign it through the equal sign, new values 1, 2, 3, and 4, which are contained within square brackets. And when the script runs, I don't want to see that output, so I will suppress it with a semicolon and press enter. Next, I want to create a loop that will go through each element of that vector and display it in the command window. So I will define my for loop, and that will be for, which is a keyword, I, just a variable I'm creating now…

Contents