I want to extend an array at the points were the array are 0.
For example an array like this:
A=[2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ];
At each zero in A i want to extend by B=[3 2 3 5];
so the new array will be:
C=[2 3 4 5 0 0 0 1 4 5 5 0 0 3 4 0 0 0 2 0 0 0 0 0];

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 4월 15일
편집: Andrei Bobrov 2019년 4월 16일

0 개 추천

A = [2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ];
B = [3 2 3 5];
out = A(sort([find(A),repelem(find(A == 0),B)]));

댓글 수: 4

madhan ravi
madhan ravi 2019년 4월 15일
What is ii ?
Rikke
Rikke 2019년 4월 16일
편집: Rikke 2019년 4월 16일
@Andrei
I wrote wrong in the first place, i want all the zeros to exceed so B will be for example:
B= [3 2 3 5];
out will then be =[2 3 4 5 0 0 0 1 4 5 5 0 0 3 4 0 0 0 2 0 0 0 0 0];
Andrei Bobrov
Andrei Bobrov 2019년 4월 16일
Hi Rikke!
I fixed my answer.
Rikke
Rikke 2019년 4월 17일
Brilliant! Thanks!

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

추가 답변 (1개)

Rikke
Rikke 2019년 4월 16일

0 개 추천

I got the solution for B= [3 2 3 5]. Thanks Andrei!
A=[2 3 4 5 0 1 4 5 5 0 3 4 0 2 0 ];
B=[3 2 3 5];
jj = find(A == 0);
out = A(sort([find(A),jj,repelem(jj,B)]));
Madhan I think ii is if you want to add zeros to spesific zeros in the array and not all of them.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2019년 4월 15일

댓글:

2019년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by