How do I use numerical and logical indices to get this output?

2 ビュー (過去 30 日間)
Luming Tan
Luming Tan 2021 年 2 月 24 日
コメント済み: Luming Tan 2021 年 2 月 25 日
Provide Matlab code that generates the following output. Given the vectors:
myArray = [2, 4, -3, 6, 9]
How do I use numerical indices and logical indices to get this:
myArray = [2, 4, 1, 6, 9]

回答 (1 件)

per isakson
per isakson 2021 年 2 月 25 日
編集済み: per isakson 2021 年 2 月 25 日
One out of many ways
%%
myArray = [2, 4, -3, 6, 9];
isneg = myArray < 0;
myArray( isneg ) = 1;
  1 件のコメント
Luming Tan
Luming Tan 2021 年 2 月 25 日
Appreciate!! that's exactly what I am looking for!

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by