stretching a non-monotonically increasing vector

9 views (last 30 days)
Hi,
I have the following vector structure (optimal input returned from tomlab)
u = [0 1 1 0 1 0 0 1 0] and I want to stretch it so I obtain
u_new = [0 0 0.5 1 1 1 1 0.5 0 0 0.5 1 1 0.5 0 0 0 0 0.5 1 1 0.5 0 0]
where all values must remain between the upper and lower values from the original array.
interp1 is not suited, imresize does not seem to do the trick either. Any suggestions are appreciated

Answers (3)

Guillaume
Guillaume on 28 Feb 2015
Can you explain the rule you used to create your u_new? (and why its number of elements is not a multiple of the original).
I can get fairly close with:
u_new = floor(2 * imresize(u, 3, 'bilinear')) / 2;
u_new = u_new(1, :)

Michiel
Michiel on 28 Feb 2015
okay, I don't have the rule, if I did I would not ask the question :). But it is a bit more complicated
the true optimal input vector (u) I have varies. It contains 60 elements always, which are any value between 0 and 1 and describe a trajectory in between a sine wave and step functions (thus, domains going up, domains going down, and at certain intervals constantly 0 or 1), at non-regularly spaced time intervals, looking like: t=[1:variable:19.9]' in my case.
now I want to "stretch" this, by which I mean interpolate the data, such that I obtain the values at 200 regularly spaced time intervals (t=[1:0.1:19.9]')
  1 Comment
Guillaume
Guillaume on 2 Mar 2015
Please use 'Comment on this Answer' rather than starting a new answer.
You must have followed some rule to create your example of u_new. Furthermore, you must have some rule for saying that the result produced by "interp1 is not suited" and that "imresize does not seem to do the trick either".
We can attempt to provide solutions ad nauseam, but without any criteria for what the result should be, we'll be here forever.

Sign in to comment.


Jos (10584)
Jos (10584) on 1 Mar 2015
You do want to take a look at interp1
t = [1 3 4 6 9] ; % irregular time intervals
y = [0 1 1 0 1] ;
t1 = 1:9 ; % regular time intervals
y1 = interp1(t,y,t1,'linear')

Community Treasure Hunt

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

Start Hunting!