フィルターのクリア

How to use all the other indices except of the ones given in an array?

344 ビュー (過去 30 日間)
Emmanouil  Rachoutis
Emmanouil Rachoutis 2018 年 12 月 8 日
I have a vector let's say A = [1:1:100]', vector B = [1:0.5:50.5]' and a third vector with some indices such us idx = [10 11 30 35 40 90 91 92 93 99]'. I would like set the values of A corresponding to the idx to 0 and the values of B that do not correspond to the idx to 0, somethike like: A(idx) = 0 and B(~idx) = 0.

採用された回答

Bruno Luong
Bruno Luong 2018 年 12 月 8 日
A(idx) = 0;
B(setdiff(1:end,idx)) = 0;
  1 件のコメント
Emmanouil  Rachoutis
Emmanouil Rachoutis 2018 年 12 月 8 日
This works as well! Thanks for the fast response :)

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

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 12 月 8 日
編集済み: madhan ravi 2018 年 12 月 8 日
Make those indices logical:
A = (1:100).';
B = (1:0.5:50.5).';
Linear_indices= [10 11 30 35 40 90 91 92 93 99].';
idx=ismember(1:numel(A),Linear_indices); % idx is logical indices
A(idx) = 0
B(~idx) = 0

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by