From the course: MATLAB 2018 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Perform operations multiple times using for loops - MATLAB Tutorial
From the course: MATLAB 2018 Essential Training
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
-
-
-
-
-
-
Include if and if-else statements in a script7m 28s
-
(Locked)
Apply conditional logic using Switch5m 26s
-
(Locked)
Examine values using the is statements3m 21s
-
(Locked)
Use is statements3m 45s
-
(Locked)
Perform operations multiple times using for loops7m 29s
-
(Locked)
Perform operations while a specific condition is true5m 19s
-
-
-
-