필터 지우기
필터 지우기

getting a matrix out of a matrix

조회 수: 1 (최근 30일)
Dwyane  Wade
Dwyane Wade 2011년 8월 15일
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
Walter Roberson
Walter Roberson 2011년 8월 15일
Experience.
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