Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how to index a vector by another one?

3 visualizaciones (últimos 30 días)
Aiachi Hiba
Aiachi Hiba el 11 de Mayo de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
idx=[-2,-1,0,1,2,3];
x=[6,5,2,1,8,0];
is there a way to get that x(-2)=6,...,x(3)=0

Respuestas (1)

Star Strider
Star Strider el 11 de Mayo de 2017
MATLAB indexing begins with 1 and includes all non-negative integers.
You have to do something like this:
idx=[-2,-1,0,1,2,3];
x=[6,5,2,1,8,0];
Result = x(idx+abs(min(idx))+1);
  1 comentario
Stephen23
Stephen23 el 11 de Mayo de 2017
Why the abs? I am not sure that it helps. Perhaps:
Result = x(idx+1-min(idx))

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by