Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column selection in Matlab

Tags:

matrix

matlab

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.

like image 277
Ramala Avatar asked Apr 12 '11 20:04

Ramala


People also ask

How do I select all elements in a column in MATLAB?

If you want to access all of the rows or columns, use the colon operator by itself.

How do you select a column in a matrix?

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.

How do you select a random column in MATLAB?

Use the randperm function. cols = randperm(200, 160);

How do you do columns in MATLAB?

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.


1 Answers

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.

like image 143
jmbr Avatar answered Oct 14 '22 06:10

jmbr