stretching a non-monotonically increasing vector

3 次查看(过去 30 天)
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

回答(3 个)

Guillaume
Guillaume 2015-2-28
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 2015-2-28
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 个评论
Guillaume
Guillaume 2015-3-2
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.

请先登录,再进行评论。


Jos (10584)
Jos (10584) 2015-3-1
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')

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by