



Both can typically be used interchangeably, but it is easier to create an infinite while loop than an infinite for loop. There are two types of loops common in MATLAB, the for loop and the while loop. Loops: Loops are used when you want to perform an action multiple times.So if you wanted to get the value 3 from the z example, you would simply type z. You can then reference the number stored at any position in the vector by typing z, where “i” is the Fifth position in the vector. If you then wanted to add on to z, you could simply state z = 3. To set a variable to a single number, simply type something like z =1. In the case of MATLAB, array size does not need to be specified when the variable is created. This means that variables are stored as lists of numbers, with the most basic list containing only one number. Variable Types: The only type of variable in MATLAB is an array.You can also type “clear” followed by a variable name to clear only the data for that specific variable. Typing “clear” in the command window after the > prompt will clear all current variables, which can help if you're seeing unusual output. Clear Command: There are a few useful command window commands.Also, any time that an output is desired, like a graph, the semicolon should be omitted. This is trivial when the output is a short assignment, like y = 1, but becomes problematic if a large matrix is created. Semi-colon Operator: If a command is followed by a ' ' then the output will not be printed on the screen.
