MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB索引问题 (https://www.labfans.com/bbs/showthread.php?t=26244)

poster 2019-12-14 20:13

MATLAB索引问题
 
例如,我有一个矩阵

A = [ 1 2 3; 4 5 6; 7 8 9] ; 和一个大小为1x3的向量,它指定每行中的哪个元素是我要寻找的元素-即如果

vector = [ 1 2 1 ] 那么所需的输出是

[ 1 5 7 ] 因为1是第1行中的第1元素,所以5是第2行中的第2个元素,而7是第3行中的第1个元素。

我该如何实现?找不到内置函数来执行此操作,这让我感到惊讶。



[B]回答:[/B]

首先,Matlab中的索引从上到下。
因此,在您的情况下, [B]A [1] = 1,A [2] = 4,A [3] = 7[/B]

就是说,对A'进行操作会更容易,因为它更琐碎。

B = A'; B((vector + [0:2].* 3))

[url=https://stackoverflow.com/questions/4842512]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:22

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.