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 while a specific condition is true - MATLAB Tutorial
From the course: MATLAB 2018 Essential Training
Perform operations while a specific condition is true
- [Instructor] Some loops let you repeat actions a set number of times, such as the number of values in a vector. Sometimes, you'll either face random or unknown inputs and need the loop to stop when limit is reached or before. In this movie, I will show you how to use a while loop to prevent MATLAB from exceeding a value. I am in a blank command window, but what I need to do is create a script. So on the home tab, I will click New Script. Or I could've also pressed control N. The scenario that I have in mind is one where I have a container and I can load it up to a certain weight, but I absolutely cannot go over. That means that I need to check the weight as I go, and refuse an item that would put the box over its weight limit. I will start by defining a variable called totalweight and assign it the value of zero and I'll follow that with a semicolon so I don't get any output. Then nextitem also equals zero. I'm initializing these variables to zero. They will change later. Then…
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
-
-
-
-