Borrar filtros
Borrar filtros

How to increase elements of a vector without changing its plot?

25 visualizaciones (últimos 30 días)
Alessandro Longo
Alessandro Longo el 24 de Nov. de 2017
Comentada: Shuntao Ji el 28 de Jul. de 2018
Hello forum, I have a vector of x elements (57x1) that I would expand to a y-size vector (3000, for example) but without changing its plot (it is a particular stairs plot). Any idea on how to do it?

Respuestas (2)

Jan
Jan el 24 de Nov. de 2017
Editada: Jan el 24 de Nov. de 2017
What about a "nearest" interpolation?
Y = interp1(1:length(X), X, linspace(1, length(X), 3000), 'nearest')
Then Y contains only values of X, but sampled with a higher frequency. Another simpler approach:
t = round(linspace(1, length(X), 3000));
Y = X(t);

KL
KL el 24 de Nov. de 2017
If you have
X = rand(57,1); %57 elements
if you want to have 3000 elements now,
X(end+1:end+3000,1) = rand(3000,1);
if you only want to plot the first 57 elements,
plot(X(1:57,1))
  2 comentarios
Alessandro Longo
Alessandro Longo el 24 de Nov. de 2017
But the shape changes. I tried to plot X(1:57,1) and X, there are two different shapes. In particular, I need this plot, that is defined by a vector of 57 elements (so my X is 57x1), but defined by a vector of 3000 elements (so X 3000x1 but the same plot!)
KL
KL el 24 de Nov. de 2017
Editada: KL el 24 de Nov. de 2017
I'm not clear with what do you mean. Please show me how you create these vectors.
If you want to create more number of elements between the same limits, use linspace.
x_57 = linspace(1,30,57);
x_3000 = linspace(1,30,3000);
if you want to "append" more elements to the first vector ( x_57), then
x_57_new = [x_57 newVector]

Iniciar sesión para comentar.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by