Join elements of an array
古いコメントを表示
If I have two array
a=[1 2 3 0]
b=[0 0 5 4]
and I want the array c=[1 2 3 4] How should I proceed?
In other words I want a array c in which the element of array a==0 is replaced with the element of matrix b.
1 件のコメント
Image Analyst
2015 年 7 月 12 日
What happened to the 5? Why did you leave that out of c?
回答 (1 件)
Azzi Abdelmalek
2015 年 7 月 12 日
編集済み: Azzi Abdelmalek
2015 年 7 月 12 日
a=[1 2 3 0]
b=[0 0 5 4]
idx=a==0
bb=sort(nonzeros(b))
a(idx)=bb(1:sum(idx))
2 件のコメント
fede
2015 年 7 月 12 日
編集済み: Azzi Abdelmalek
2015 年 7 月 12 日
Azzi Abdelmalek
2015 年 7 月 12 日
Have you tried my code?
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!