Tutorial by Examples

There is already a function sum(). As a result, if we name a variable with the same name sum = 1+3; and if we try to use the function while the variable still exists in the workspace A = rand(2); sum(A,1) we will get the cryptic error: Subscript indices must either be real positive integer...
This a basic example aimed at new users. It does not focus on explaining the difference between char and cellstring. It might happen that you want to get rid of the ' in your strings, although you never added them. In fact, those are artifacts that the command window uses to distinguish between ...
.' is the correct way to transpose a vector or matrix in MATLAB. ' is the correct way to take the complex conjugate transpose (a.k.a. Hermitian conjugate) of a vector or matrix in MATLAB. Note that for the transpose .', there is a period in front of the apostrophe. This is in keeping with the ...
This is MATLAB's long-winded way of saying that it cannot find the function that you're trying to call. There are a number of reasons you could get this error: That function was introduced after your current version of MATLAB The MATLAB online documentation provides a very nice feature which allow...
Floating-point numbers cannot represent all real numbers. This is known as floating point inaccuracy. There are infinitely many floating points numbers and they can be infinitely long (e.g. π), thus being able to represent them perfectly would require infinitely amount of memory. Seeing this was a ...
Often beginning MATLAB developers will use MATLAB's editor to write and edit code, in particular custom functions with inputs and outputs. There is a Run button at the top that is available in recent versions of MATLAB: Once the developer finishes with the code, they are often tempted to push th...
Some common operations in MATLAB, like differentiation or integration, output results that have a different amount of elements than the input data has. This fact can easily be overlooked, which would usually cause errors like Matrix dimensions must agree. Consider the following example: t = 0:0.1:1...
Recommendation Because the symbols i and j can represent significantly different things in MATLAB, their use as loop indices has split the MATLAB user community since ages. While some historic performance reasons could help the balance lean to one side, this is no longer the case and now the choice...
A common mistake MATLAB coders have, is using the length function for matrices (as opposed to vectors, for which it is intended). The length function, as mentioned in its documentation, "returns the length of the largest array dimension" of the input. For vectors, the return value of leng...

Page 1 of 1