0

I have an array that looks like this;

arr_with_zeros = [1 0 0 2 0 0 3 0 0 6 0 0 8 0 0]

I want to replace the zeros with the last non-zero value in the array. The new array should look like this;

arr_non_zeros = [1 1 1 2 2 2 3 3 3 6 6 6 8 8 8]

This is the code I wrote.

arr_non_zeros = ValueWhen(True, arr_with_zeros, n=1);

It does not work. arr_non_zeros has the same contents as arr_with_zeros. Can someone help? Thank you.

I am using Amibroker ver6.30.5

user3848207
  • 3,737
  • 17
  • 59
  • 104

1 Answers1

1

Have a look at IIF

arr_new = iif(arr_non_zeros == 0, ref(arr_non_zeros,-1), arr_non_zeros);
Sethmo011
  • 575
  • 7
  • 20