フィルターのクリア

operations in a row only on certain elements

1 回表示 (過去 30 日間)
EllaD
EllaD 2020 年 4 月 5 日
編集済み: Tommy 2020 年 4 月 5 日
Hi,
I have a row in a matrix, say A(1,:). I also have a vector b which its elemants are indices, I want to set to zero elements in A(1,:) where its index is NOT included in b. How can I do this?
Example:
A=[1 3 4; 5 6 2; 1 4 2]
b=[ 3 2]
So for the first row of A, I want to have A=[0 3 4; 5 6 2; 1 4 2]
the 2nd and 3rd index are not set to zero.
Thanks in advance.

採用された回答

Tommy
Tommy 2020 年 4 月 5 日
編集済み: Tommy 2020 年 4 月 5 日
See if this works:
idx(b) = true;
A(1,~idx) = 0;
  2 件のコメント
EllaD
EllaD 2020 年 4 月 5 日
編集済み: EllaD 2020 年 4 月 5 日
My bad, cleared everything and it actually works! Thanks!
Tommy
Tommy 2020 年 4 月 5 日
編集済み: Tommy 2020 年 4 月 5 日
Happy to help!

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

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