フィルターのクリア

Seperately extract 11th and 21st element of matrix A

1 回表示 (過去 30 日間)
N/A
N/A 2022 年 8 月 28 日
コメント済み: Star Strider 2022 年 8 月 28 日
Hi,
I took Mathlab programming this semester and am still new to all of this.
So basically, I've been given this matrix A (5x5) as shown below.
A=[17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3; 11 18 25 2 9]
So my question is, how do I extract 11th and 21st element of matrix A?
Thank you.
  4 件のコメント
Torsten
Torsten 2022 年 8 月 28 日
編集済み: Torsten 2022 年 8 月 28 日
A_11_and_21 = [A(3,1),A(5,1)]
dpb
dpb 2022 年 8 月 28 日
<learn_matlab/array-indexing.html> is section in Getting Started doc about addressing arrays including this which is called linear indexing.
If in addition to the example you really were interested in traversing the array by row instead of column, then
M = reshape((1:25).', 5, [])*10;
M=M.'; % transpose first
V = M([11 21])
V = 1×2
30 50

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

採用された回答

Star Strider
Star Strider 2022 年 8 月 28 日
移動済み: Matt J 2022 年 8 月 28 日
MATLAB generally uses columnwise linear indexing, so:
M = reshape((1:25).', 5, [])*10
M = 5×5
10 60 110 160 210 20 70 120 170 220 30 80 130 180 230 40 90 140 190 240 50 100 150 200 250
V = M([11 21])
V = 1×2
110 210
.
  2 件のコメント
N/A
N/A 2022 年 8 月 28 日
移動済み: Matt J 2022 年 8 月 28 日
Got it, thanks so much for your help! :)
Star Strider
Star Strider 2022 年 8 月 28 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by