Matlab- Round Brackets Flashcards
to enter most data in Matlab you need to use
brackets []
how do you put data into a column vector?
type the values in square brackets and separate them by using ;
how would the data look like? D = [3; 1; 6; 5]
D = 3
1
6
5
how do you put data into a matrix?
use , to separate the number (rows) and use ; to separate lines (column)
how would this look like?
E = [1, 2, 3; 4, 5, 6]
E = 1 2 3
4 5 6
round brackets () are used for?
to refer to a part of a matrix
if you used E(2,3) and the matrix was
E = 1 2 3
4 5 6
what would be the output?
ans = 6
(explanation: the first number refers to the rows, the second number refers to the columns)
what would be the output for this?
E(4,3)
matrix:
E = 1 2 3
4 5 6
error message
explanation: it calls for numbers that don’t exist in the matrix.
how do you change numbers of a matrix using round brackets
In one line: call the matrix, use brackets, in the brackets establish the place in the matrix, use = to replace the number in that location
what would the line of code be to change
matrix: E = 1 2 3
4 5 6
to this:
E = 1 2 10
4 5 6
E (1,3) = 10
how would you change an entire row in a matrix?
use round brackets and square brackets
how would you add a row or column into a matrix?
use round brackets, a colon to call the entire row or column and then = and square brackets to insert the new numbers.
note: the dimensions have to stay the same.