problem indexing a matrix from arrays

1 回表示 (過去 30 日間)
Tristan
Tristan 2013 年 10 月 31 日
回答済み: Azzi Abdelmalek 2013 年 10 月 31 日
I want matlab to return all the elements of p2 at rows r columns c, I tried p2(r,c), but that doesn't give me the right answer.
p2 =
0.1500 0.1500
0.4804 0.4804
0.5098 0.5098
0.0498 0.0498
1.1008 1.1008
1.0920 1.0920
2.0219 2.0219
1.1342 1.1342
2.9643 2.9643
3.8808 3.8808
3.8487 3.8487
4.9765 4.9765
8.3789 8.3789
7.7730 7.7730
r =
3
6
7
9
10
12
3
6
7
9
10
12
c =
1
1
1
1
1
1
2
2
2
2
2
2
>> p2(r,c)
ans =
Columns 1 through 5
0.5098 0.5098 0.5098 0.5098 0.5098
1.0920 1.0920 1.0920 1.0920 1.0920
2.0219 2.0219 2.0219 2.0219 2.0219
2.9643 2.9643 2.9643 2.9643 2.9643
3.8808 3.8808 3.8808 3.8808 3.8808
4.9765 4.9765 4.9765 4.9765 4.9765
0.5098 0.5098 0.5098 0.5098 0.5098
1.0920 1.0920 1.0920 1.0920 1.0920
2.0219 2.0219 2.0219 2.0219 2.0219
2.9643 2.9643 2.9643 2.9643 2.9643
3.8808 3.8808 3.8808 3.8808 3.8808
4.9765 4.9765 4.9765 4.9765 4.9765
Columns 6 through 10
0.5098 0.5098 0.5098 0.5098 0.5098
1.0920 1.0920 1.0920 1.0920 1.0920
2.0219 2.0219 2.0219 2.0219 2.0219
2.9643 2.9643 2.9643 2.9643 2.9643
3.8808 3.8808 3.8808 3.8808 3.8808
4.9765 4.9765 4.9765 4.9765 4.9765
0.5098 0.5098 0.5098 0.5098 0.5098
1.0920 1.0920 1.0920 1.0920 1.0920
2.0219 2.0219 2.0219 2.0219 2.0219
2.9643 2.9643 2.9643 2.9643 2.9643
3.8808 3.8808 3.8808 3.8808 3.8808
4.9765 4.9765 4.9765 4.9765 4.9765
Columns 11 through 12
0.5098 0.5098
1.0920 1.0920
2.0219 2.0219
2.9643 2.9643
3.8808 3.8808
4.9765 4.9765
0.5098 0.5098
1.0920 1.0920
2.0219 2.0219
2.9643 2.9643
3.8808 3.8808
4.9765 4.9765
I should be getting this:
0.5098
1.092
2.0219
2.9643
3.8808
4.9765
0.5098
1.092
2.0219
2.9643
3.8808
4.9765

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 31 日
p2(sub2ind(size(p2),r,c))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by