Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to index a vector by another one?

3 ビュー (過去 30 日間)
Aiachi Hiba
Aiachi Hiba 2017 年 5 月 11 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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

回答 (1 件)

Star Strider
Star Strider 2017 年 5 月 11 日
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 件のコメント
Stephen23
Stephen23 2017 年 5 月 11 日
Why the abs? I am not sure that it helps. Perhaps:
Result = x(idx+1-min(idx))

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by