フィルターのクリア

finding an output from a matrix using a single syntax

1 回表示 (過去 30 日間)
Dwyane  Wade
Dwyane Wade 2011 年 8 月 13 日
Hi there guys I have a question. How do you get a single line 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:
R = [33 9 30 74 -4 72 63 15]
how do I get it using a single syntax? I've been struggling since I am just new into using Matlab. please help me...
  1 件のコメント
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 13 日
What is the logic? How do you make the selection?

サインインしてコメントする。

採用された回答

Paulo Silva
Paulo Silva 2011 年 8 月 13 日
R=[Q(3:6:18) Q(21:6:45)]
Edit, there's one shorter version
R=Q([3:6:18 21:6:49])
  3 件のコメント
Dwyane  Wade
Dwyane Wade 2011 年 8 月 15 日
how did you get this?
Paulo Silva
Paulo Silva 2011 年 8 月 15 日
Please read what I said in your other similar question and also http://www.mathworks.in/help/techdoc/math/f1-85462.html

サインインしてコメントする。

その他の回答 (3 件)

Dwyane  Wade
Dwyane Wade 2011 年 8 月 13 日
Im not sure what the logic is, all I know is that we are required to find R = [33 9 30 74 -4 72 63 15] using a single syntax like: R = (solution) << something like this
  1 件のコメント
Paulo Silva
Paulo Silva 2011 年 8 月 13 日
The values are clearly in diagonals / , see my answer.

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2011 年 8 月 13 日
There is a way to select the element using logical index. It is like this:
Ind=false(size(Q));
Ind(3,1)=true;
Ind(2,2)=true;
Ind(1,3)=true;
Ind(7,3)=true;
R=Q(Ind)
You'll get the idea.
Or linear indexing
LinInd=[1 12 20 40];
S=R(LinInd)

Andrei Bobrov
Andrei Bobrov 2011 年 8 月 13 日
a=spdiags(Q(end:-1:1,:))
a1=a(:,[3,9])
out=a1(a1~=0)
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 8 月 13 日
about logic:
a=spdiags(Q(end:-1:1,:))
a1=a(:,[0,size(Q,1)-1]+3)
out=a1(a1~=0)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by