Clear Filters
Clear Filters

getting a matrix out of a matrix

1 view (last 30 days)
Hi there guys I have a question. How do you get an output out of a matrix? for example here is the matrix:
Q =
10 20 30 40 50 60 70
8 9 10 11 12 13 14
33 30 27 24 21 18 15
28 35 42 49 56 63 70
36 45 54 63 72 81 90
-1 -2 -3 -4 -5 -6 -7
64 69 74 79 84 89 94
and I am required to find:
S=
20 40 60
9 11 13
30 24 18
how do I get it using a single syntax? I've been struggling since I am just new into using Matlab. please help me...

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 15 Aug 2011
Q(1:3,[2 4 6])
  5 Comments
Paulo Silva
Paulo Silva on 15 Aug 2011
example Q=[1 3;2 4] , I choose the numbers so they are equal to the index positions:
Q(1) is 1
Q(2) is 2
Q(3) is 3
Q(4) is 4
MATLAB allows you to create vectors like this
1:3
ans=
1 2 3
You can use those vector to select certain index values like this:
Q(1:3) % the same as Q([1 2 3])
ans=
1 2 3
Another way to do it is with row and column numbers, notice the comma (,)
Q(1,2) is 3
Q(1,1) is 1
Other things to remember
The word end
Q(end) is the value of the last index, in this case is 4
The :
Q(:) means all values of Q, they appear in rows
The size function
size(Q) is 2 2 this means two rows and two columns
Q(1:2:end) in this case gives 1 3 the meaning is all values at index 1 until the end, the 2 is your step, try 1:2:4
Please read the documentation http://www.mathworks.in/help/techdoc/math/f1-85462.html

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!