# matlab - 在Matlab中获取给定坐标的值

``````s = [
0.0    0.4    0.5    0.6    0.9
0.4    0.0    0.3    0.4    0.5
0.5    0.3    0.0    0.5    0.8
0.6    0.4    0.5    0.0    0.6
0.9    0.5    0.8    0.6    0.0
]
``````

• `A`应包含坐标和反向坐标的值。 即，在此示例中，`A`包含`(1,2)``(2,1)``(4,5)``(5,4)`的值。那就是：`A=[0.4, 0.4, 0.6, 0.6]`

• `B`包含其余值，因此`B=[0, 0.5, 0.6, 0.9, 0, 0.3, 0.4, 0.5, 0.5, 0.3, 0, 0.5, 0.8, 0.4, 0.5, 0, 0.9, 0.5, 0.8, 0.6, 0]`

``````linindices = sub2ind(size(s), coordinates(:, 1), coordinates(:, 2))';
A = s(linindices)
B = s(setdiff(1:numel(s), linindices))
``````

#### 1 个答案:

``````    c=[1 2; 4 5];
s=[0 0.4 0.5 0.6 0.9
0.4 0 0.3 0.4 0.5
0.5 0.3 0 0.5 0.8
0.6 0.4 0.5 0 0.6
0.9 0.5 0.8 0.6 0];
Av=[c; fliplr(c)]
Ac=s(sub2ind(size(s),A(:,1),A(:,2)))
B=s(setdiff(1:numel(s),sub2ind(size(s),A(:,1),A(:,2))))'

Av =

1     2
4     5
2     1
5     4

Ac =

0.4000
0.6000
0.4000
0.6000

B =

0
0.5000
0.6000
0.9000
0
0.3000
0.4000
0.5000
0.5000
0.3000
0
0.5000
0.8000
0.6000
0.4000
0.5000
0
0.9000
0.5000
0.8000
0
``````

0条回复