MATLAB: Concatenate matrix numbers linspace

concatenate; matrix;linspacematrix

Hi there,
I have a matrix variable x = [0 1 2 3]
I want to generates linearly spaced vectors in between the numbers into a variable. My problem here is concatenate the numbers into p the next time n increases.
I know i should be using linspace to generate number for eg:
for i = 1:(length(x)-1)
p = linspace(x(i),x(i+1),0.5)
end
the results i want is:
p = 0 0.5 1 1.5 2 2.5 3
Hope someone can shed some light here.

Best Answer

try this
x = [0.25 1 1.5 2 2.4 2.6]
x=unique(sort([x x(1:length(x)-1)+diff(x)/2]) )
if you want put 2^n-1 samples between each value use this function
function y=linspace_n(x,n)
for k=1:n
x=unique(sort([x x(1:length(x)-1)+diff(x)/2]) )
end
y=x
Related Question