To define a column vector:
v = [1; 2; 3]
To define a row vector, two syntaxes are possible:
v = [1 2 3]
v = [1, 2, 3]
To define a matrix:
M = [1 2 3; 4 5 6; 7 8 9]
$$
\begin{bmatrix}
1 & 2 & 3
4 & 5 & 6
7 & 8 & 9
\end{bmatrix}
$$
Get element from a vector v
:
<i>
-position: v(<i>)
Get element from a matrix M
:
<i>
-row and <j>
-column: M(<i>,<j>)
<i>
-row: M(<i>,:)
<j>
-column: M(:,<j>)
<j>
-<k>
-columns: M(:,[<j>,<k>])
<i>
-<k>
-rows: M([<i>,<k>],:)
The struct()
method allows to save data in the form <field>, <value>
.
g = list("g1", "g2", "g3") p = struct() for i = g p(i) = i end fn = fieldnames(p) for j = fn' disp(p(j)) end