getting a matrix out of a matrix

1 次查看(过去 30 天)
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...

采纳的回答

Andrei Bobrov
Andrei Bobrov 2011-8-15
  5 个评论
Paulo Silva
Paulo Silva 2011-8-15
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by