Join elements of an array

조회 수: 3 (최근 30일)
fede
fede 2015년 7월 12일
댓글: Image Analyst 2015년 7월 12일
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
Image Analyst 2015년 7월 12일
What happened to the 5? Why did you leave that out of c?

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
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
fede 2015년 7월 12일
편집: Azzi Abdelmalek 2015년 7월 12일
mmmm but if i want a general formula? I have two arrays of prices.
a=[p1 p2 p3 0 0 0 ....]
b=[0 0 p3 p4 p5 0 0....]
and I want join the two arrays to obtain a array c in which I have
c=[p1 p2 p3 p4 p5]
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 12일
Have you tried my code?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by