Replace array elements with another small array using indexing
古いコメントを表示
Hi everyone,how to replace array with another small array using indexing
a=[1 1 4 1 3 3 1 1 1 3 4 1 0 0 0 0 0 0 0 0 0];
%replace 1 4 1 with 0 3 0 and 3 4 1 with 2 and b=b(b~=0); to get a new vector
b=[1 3 3 3 1 1 1 2];
Thank you.
3 件のコメント
Matt J
2020 年 5 月 19 日
%replace 1 4 1 with 0 3 0
The output you've shown has 1 4 1 replaced with 3, not with 0 3 0.
TEJAS PHUTANE
2020 年 5 月 19 日
TEJAS PHUTANE
2020 年 5 月 19 日
回答 (1 件)
Matt J
2020 年 5 月 19 日
b=strrep( strrep(a,[1 4 1],3) ,[3 4 1],2)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!