Ojage S
Ojage S

Reputation: 125

How can I extract a submatrix in scilab

I have a 4×4 matrix A =

4   3   2   1
3   2   1   0
0   1   2   3
2   1   0   -1

I want to extract the 2nd, 3rd and 4th row with the 1st, 2nd and 4th column, skipping the 3rd column.

I have tried A(2:4,1:4), but it also extracts the 3rd column which I don't want. So I did this

submatrix = A(2:4,1:4)
submatrix(:,3) = []

It works fine. But is there a way I could do it with one instruction?

Upvotes: 1

Views: 886

Answers (1)

Stéphane Mottelet
Stéphane Mottelet

Reputation: 3014

try

submatrix = A(2:4,[1 2 4])

Upvotes: 1

Related Questions