Frequently Asked questions
Help us populate this list! If you have a question, it is very likely that somebody else has it, too, and will benefit from us answering it.
Index of Questions
- MATLAB got stuck computing something and is irresponsive. Do I need to abort the program and restart it? What else can I do? Answer
- What is the difference between an array and a vector? Answer
- What is the negation operator (logical NOT) in MATLAB? Answer
- What's the difference between the & and && operators, or between | and || ? Answer
Questions and Answers
-
MATLAB got stuck computing something and is irresponsive. Do I need to abort the program and restart it? What else can I do?
Simply hit Ctrl-C to stop the computation. It might take a little while to get back, but it will.
-
What is the difference between an array and a vector?
Answer: We usually reserve the word "vector" to denote an array that consists of only one column , i.e. is m-by-1, or only one row, i.e is 1-by-n. An array in MATLAB is a generic word that can mean a vector, a matrix, or a higher dimensional object, such as a "matrix" with three or more indices. Even a scalar is a 1-by-1 array in MATLAB.
-
What is the negation operator (logical NOT) in MATLAB?
Answer: The negation operator in Matlab is ~ (a tilde) as opposed to ! (exclamation sign) for many other languages.
-
What's the difference between the & and && operators, or between | and || ?
Short Answer: && (AND), || (OR) take two scalar logical operands whereas & and | take two logical arrays.
Longer explanation. For producing a (single) boolean result, i.e. a TRUE/FALSE value, as in
if
andwhile
conditions, you should use && (AND), || (OR) on operands that are scalars (so that the evaluated result is a scalar). The operators & and | are used for vectorized computing, i.e. component wise AND and OR operations over operands that are arrays of the same size. As it is not clear whatif (v) ... end
should do, wherev
is a vector such asv= [true false false true]
, you should avoid using logical vectors in place of conditions that should have a single truth value.That's right! The single character versions (& and |) are for producing multiple results at once (i.e. logical vectors), whereas the double character (&& and ||) versions are meant for producing single results.
You will learn everything about vectorized logical operations and how to use them in Module 2, part 2. of our course. For the beginning of the course please avoid & and |.