This is very basic, but please forgive me since I'm only familiar with python and am trying to translate this code over from matlab. Basically, I have two variables:
```
var1 = [139,
140,
142,
143,
144,
154,
156,
157,
158,
159,
184,
185,
186,
187,
188,
189,
190,
191,
192]
var2 = [11,
12,
12,
15,
10,
8,
7,
10,
9,
6,
10,
9,
8,
15,
5,
17,
15,
18,
14,
18,
16,
13,
13,
17,
19,
4,
15,
18,
1,
4,
2,
3,
3,
1,
9]
```
All fine and good. Except that there is a separate variable, call it var3, which is defined as:
```
var3 = var1(var2);
```
which results in the value:
```
var3 = [184,
185,
185,
188,
159,
157,
156,
159,
158,
154,
159,
158,
157,
188,
144,
190,
188,
191,
187,
191,
189,
186,
186,
190,
192,
143,
188,
191,
139,
143,
140,
142,
142,
139,
158]
```
I'm confused as to what operation is occurring to get this resultant value of var3. Any help would be greatly appreciated.

回答 (1 件)

John D'Errico
John D'Errico 2023 年 4 月 16 日

0 投票

var2 is used as an index. It extracts the corresponding element of var1, thus creating var3.

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

製品

質問済み:

2023 年 4 月 16 日

回答済み:

2023 年 4 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by