How to extract value from some row or column in a matrix

378 ビュー (過去 30 日間)
Tran Hoa
Tran Hoa 2019 年 1 月 19 日
コメント済み: Afluo Raoual 2021 年 2 月 8 日
Dear members
I have two matrix
A is a matrix that has 100 row=[1 2 3 4 5 6 7 8 9 10 ......100]
B is a matrix that wants to get the value from row 1 to row 10, and from row 25 to row 35
How to get matrix B
Thank you
  1 件のコメント
Image Analyst
Image Analyst 2019 年 1 月 19 日
Terminology note: your A is a special kind of matrix called a "row vector" since it is a horizontal list of 100 numbers. It has 100 columns, not 100 rows. It has only one row.
So not exactly sure what you have, but madhan gives several options to choose from below in his answer, depending on what you have.

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

採用された回答

madhan ravi
madhan ravi 2019 年 1 月 19 日
編集済み: madhan ravi 2019 年 1 月 19 日
By indexing like shown below:
% if A is a matrix
A=rand(100); % fake data
B=A([1:10 25:35],:) % extracts specified rows
B=A(:,[1:10 25:35]) % extracts specified columns
% if A is a vector then
A=1:100; % fake data (row vector) , (1:100).' - column vector
B=A([1:10 25:35]) % extracts specified elements (1D-a vector)
Note: The square brackets [] is used to denote discontinuities thereby extracting the spcified elements, rows or columns.
  4 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 19 日
Anytime :)
Afluo Raoual
Afluo Raoual 2021 年 2 月 8 日
Thank you. It help

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by