Is it possible to select only particular columns of a matrix? E.g. I have a 10x100 shaped matrix and I only would like to get these 4 columns: 231, 82, 12, 493.
If you want to access all of the rows or columns, use the colon operator by itself.
To get a specific column of a matrix, specify the column number preceded by a comma, in square brackets, after the matrix variable name. This expression returns the required row as a vector.
Use the randperm function. cols = randperm(200, 160);
In MATLAB you can also create a column vector using square brackets [ ]. However, elements of a column vector are separated either by a semicolon ; or a newline (what you get when you press the Enter key). Create a column vector x with elements x1 = 1, x2 = -2 and x3 = 5.
Yes, it is possible. If your matrix is named A
then A(:, [3,7,12,89])
will retrieve the columns numbered 3, 7, 12, and 89.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With