How to extract a column from a matrix by searching

1 回表示 (過去 30 日間)
Shahar ben ezra
Shahar ben ezra 2021 年 3 月 26 日
コメント済み: dpb 2021 年 3 月 27 日
hi
I have an example of something I need
I want to take out a column in the matrix by searching in the first row
clc, clear
frequency = linspace(1,20,20);
amp = randi([-100,-60],10,20);
matrix_test = [frequency;amp]
[my_vec_For_example_num_11] = find(matrix_test==11) % I want to enter a number from 1 to 20 and take out its column
i_want_vec_11=matrix_test(1:end,11) %That should be the result,
The solution does not have to be with "find"
tnx :)

採用された回答

dpb
dpb 2021 年 3 月 26 日
vWant=11;
vecRes=matrix_test(:,matrix_test(1,:)==vWant);
  2 件のコメント
Shahar ben ezra
Shahar ben ezra 2021 年 3 月 26 日
tnx!
dpb
dpb 2021 年 3 月 27 日
Look up "logical indexing" -- one of most powerful of MATLAB features.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by