Replace rows in one array with values from another column

2 ビュー (過去 30 日間)
Aleya Marzuki
Aleya Marzuki 2019 年 8 月 14 日
回答済み: madhan ravi 2019 年 8 月 14 日
I have a long column with integers. In any 24 of the rows, there are number 5s. For example [354, 693, 5, 1289, 1890, 3456, 5 .... etc]
In a separate array, I have a list of numbers [1-4] in 24 rows, e.g. [1, 2, 2, 4, 1, 1, 3, 4, ...] until the 24th row.
How would I be able to replace the number 5s in the long array with the numbers from the 24-row array? The end output would be [354, 693, 1, 1289, 1890, 3456, 2 .... etc]
I've tried double for-loops but they don't work well (and there's definitely a way to do this without a loop that I'm just not aware of).
Thank you!

採用された回答

madhan ravi
madhan ravi 2019 年 8 月 14 日
v1(v1==5)=v2 % where v1 is array with 5s

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by