Hi
I have an array like [1 0 0 0 2 0 0 0 3 0 0 0 0 0 5 0 0 0 0].
I want output like, [1 1 1 1 2 2 2 2 3 3 3 3 3 3 5 5 5 5 5].
how i can do this?
Thanks in Advance!!!
Murugan

 채택된 답변

Stephen23
Stephen23 2018년 9월 19일
편집: Stephen23 2018년 9월 19일

0 개 추천

An old fashioned way:
>> V = [1,0,0,0,2,0,0,0,3,0,0,0,0,0,5,0,0,0,0];
>> X = V~=0;
>> U = V(X);
>> U(cumsum(X))
ans =
1 1 1 1 2 2 2 2 3 3 3 3 3 3 5 5 5 5 5

추가 답변 (1개)

jonas
jonas 2018년 9월 19일

0 개 추천

A is your array
A(A==0)=NaN
A=fillmissing(A,'previous')

댓글 수: 1

Murugan C
Murugan C 2018년 9월 20일
currently i am using lower version. I think, it should work for higher version. Thanks for your suggestion.

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

카테고리

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

질문:

2018년 9월 19일

댓글:

2018년 9월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by