Reshape array such that boundaries remain the same

1 visualización (últimos 30 días)
Emile Biever
Emile Biever el 22 de En. de 2021
Comentada: Emile Biever el 22 de En. de 2021
Dear Support,
I have a question regarding different sizes of arrays. I have for example 2 arrays that looks like this:
x =[0, 1, 2, 1, 0];
y =[0, 0.5, 1, 1.5, 2, 1.5, 1, 0.5, 0];
I want to extend in this case the array of array x to fit the size of array y. The only condition that I have is that the boundaries of array x remains the same, and that array x is a palindrome.
Can you help me with this?
Thanks in advance!
Kind regards,
Emile Biever
  2 comentarios
Emile Biever
Emile Biever el 22 de En. de 2021
Of course I am more interesting in a function on how to do this. You can see at first glance that you can make the arrays similar by placing 0.5, and 1.5 on both sides of array x.
Fangjun Jiang
Fangjun Jiang el 22 de En. de 2021
define "boundaries"

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 22 de En. de 2021
x = [0, 1, 2, 1, 0];
y = [0, 0.5, 1, 1.5, 2, 1.5, 1, 0.5, 0];
xnew = interp1(x,linspace(1,numel(x),numel(y)))
xnew = 1×9
0 0.5000 1.0000 1.5000 2.0000 1.5000 1.0000 0.5000 0

Más respuestas (0)

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by