I want to create a piecewise function that depends on the length of the list. Let's say I have a list, and a corresponding piecewise function:
list1={a,b,c}
pFun=Piecewise[{{{1, x}, x <= list1[[1]]}, {{2, x}, list1[[2]] < x <= list1[[3]]}}, {3, x}]
now say if I change the length of the list to 4,
list1={a,b,c,d}
Is there any possible way to automate the Piecewise function, such that list1[[3]] < x <= list1[[4]]
is added based on the length of the list list1
? The length of list1
keeps changing and I can't edit pFun
everytime. Any help is appreciated.
list1
in any way. (2) The gap between list1[[1]] and list1[[2]] isn't explicitly covered by the conditions. Correct? $\endgroup$