change a logical array value based on the index of another matrix

4 ビュー (過去 30 日間)
raheem mian
raheem mian 2019 年 11 月 10 日
コメント済み: raheem mian 2019 年 11 月 10 日
I have a logical matrix the same size as matrix A.
If A has a value above a threshold, I want to change the corresponding index in the logical matrix to 1.
A = [1 2 3 4 5];
x = [0 0 0 0 0];
%based on A >= 4 change x to 1 ;
%so x would be [0 0 0 1 1]

採用された回答

John D'Errico
John D'Errico 2019 年 11 月 10 日
If you want to create x on the fly, then just do this:
x = A > 4;
If you for some reason really want to modify an existing vector x, then do this:
x(A > 4) = true;

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