I have an input array 'z' with which I want to create an array 'p' in the way given below. The length and values of 'z' is varying. How I can register 'p' for every case of 'z'. Thank you

z=[-0.5,-0.25,0,0.25,0.5];
p=zeros(1,2*(length(z))-2);
p(1)=z(1);
p(end)=z(end);
and
p should look like this
p=[-0.5,-0.25,-0.25,0,0,0.25,0.25,0.5]

2 comentarios

YOu got -0.25 and +0.25 extra? How and why?
z is the coordinates of 4 layers/ply (difference gives thickness) and p is the coordinates of the top and bottom layers of each ply

Iniciar sesión para comentar.

 Respuesta aceptada

>> z = [-0.5,-0.25,0,0.25,0.5];
In two lines using repmat:
>> p = repmat(z,2,1);
>> p = p(2:end-1)
p =
-0.50000 -0.25000 -0.25000 0.00000 0.00000 0.25000 0.25000 0.50000
Or in one line using indexing:
>> p = z(ceil((2:2*numel(z)-1)/2))
p =
-0.50000 -0.25000 -0.25000 0.00000 0.00000 0.25000 0.25000 0.50000

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 3 de Oct. de 2018

Comentada:

el 3 de Oct. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by