Gistlib Logo

gistlib

take second column of matrix in matlab

You can take the second column of a matrix "A" in MATLAB using the colon operator with the index of the second column enclosed in square brackets. Here is an example:

main.m
A = [1 2 3; 4 5 6; 7 8 9];
secondColumn = A(:, 2)
50 chars
3 lines

The output will be:

main.m
secondColumn =

     2
     5
     8
37 chars
6 lines

In this example, : means all the rows of matrix A, and 2 means the second column of A.

similar matlab code snippets

display last column in matrix in matlab
how to add multiple matrices in matlab
the function mat2coord should take an n × n array representing a matrix a ∈ r n×n and return the sparse coordinate representation encoded by the three arrays, d, ridx, and cidx in matlab
how to change the diagonal of a matrix to be the sum of its position on row and column in matlab
replace last row of a matrix in matlab
design the function function out = x_m(x,m) with input data matrix x of size 𝑁 × 𝑑 hat produces the data matrix of size 𝑁 × (𝑀 + 1) in matlab
how to put rows of a matrix into a indidual cell array in matlab in matlab
how to change the diagonal of a matrix 3x3 with a vector with 3 elements in matlab
display last column in matrix with fprintf in matlab
find the coordinates of the largest value in a matrix in matlab

related categories

matrices
indexing

gistlibby LogSnag