フィルターのクリア

Access matrix location on one matrix with the data location on another matrix

1 回表示 (過去 30 日間)
Rohan  Mehta
Rohan Mehta 2019 年 6 月 21 日
編集済み: madhan ravi 2019 年 6 月 21 日
I have two matrix say A & B if I have data stored in A and the data location of desired values in B how could I access Values of matrix A who are located at locations B.

採用された回答

Chinmay Anand
Chinmay Anand 2019 年 6 月 21 日
In case if A and B are vectors ,( 1 x n ) matrices
A(B) % It will give the values of A at indexes B
  3 件のコメント
Chinmay Anand
Chinmay Anand 2019 年 6 月 21 日
idx = setdiff(1:length(A),B); % indexes which are not in B
A(idx) = 0;
Rohan  Mehta
Rohan Mehta 2019 年 6 月 21 日
Thank you so much this works !!!

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 6 月 21 日
Probably you want:
idx = setdiff(1:numel(A),B);
A(idx) = 0;
  2 件のコメント
Rohan  Mehta
Rohan Mehta 2019 年 6 月 21 日
yes Exactly what I wanted
madhan ravi
madhan ravi 2019 年 6 月 21 日
編集済み: madhan ravi 2019 年 6 月 21 日
Beware this method works even if A is a matrix more than 1 dimension unlike the other.

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

カテゴリ

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