How to select a submatrix in Matlab?

385 views Asked by At

Hello and happy new year!

I have a problem, and I can't find a solution.

I need to create these 2 matrices, C from B with submatrix.

B = [  1   2   3   4   5   6   7 
       9   7   5   3   1  -1  -3 
       4   8  16  32  64 128 256];

And I want to extract this matrix from it:

C = [  2   3   4   5
      32  64 128 256]

First I created the matrix B:

B = (1:7; 9:-2:-3; 2.^(2:8));

But with this I get an error:

C = B([1,(2:5)]; [3,(4:7)]);

Any ideas?

1

There are 1 answers

1
KKS On BEST ANSWER

That's just a grammar issue.

Just try this:

C = [B(1, 2:5); B(3, 4:7)];