Selecting Elements of Matrix Given Index Value...

6 ビュー (過去 30 日間)
Michelle De Luna
Michelle De Luna 2020 年 4 月 21 日
コメント済み: Michelle De Luna 2020 年 4 月 21 日
Hi all!
I have an array with a list of indices that I am interested in extracting from a matrix. For example, the array is [96, 106, 108...] meaning I have to select the 96th, 106th, and 108th elements from a matrix, matrix A. However, matrix A has three columns (latitude, longitude, and frequency). When I try to use a for loop to pull the given elements (all thee columns of the matrix) based on index value, I only get a value for latitude (the first column). This would defeat the purpose of my project, since I would need to have the latitude, longitude, and frequency of all of the index values I have. Any suggestions? Some code provided below:
omit = [96, 106, 108, 134, 167, 194, 200, 203]
A = [latitude longitude frequency]
for i = omit
x = A(i)
end
My output (only latitude values): [-5, -4, -3, 0, 23.5, 30, 35, 75]

採用された回答

Stephen23
Stephen23 2020 年 4 月 21 日
編集済み: Stephen23 2020 年 4 月 21 日
x = A(i,:)
Or without the loop:
x = A(omit,:)
Very basic MATLAB indexing like this is explained in the introductory tutorials:
  1 件のコメント
Michelle De Luna
Michelle De Luna 2020 年 4 月 21 日
Stephen, thank you for your help! And thank you for the link - I'll be sure to review it! Again, thank you! :)

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

その他の回答 (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