i have data A=( 3,5,3,1,4 ) in a column and
B=[ 4 6 9 1 3
2 7 2 5 7
7 3 1 8 2
4 1 6 9 1
2 5 8 3 6]
and i want: as in A first element is 3 and for this i want to get first element of column 3 row 1 from B which is 9. The second element of A is 5 and for this i want to get the the 2nd element of column 5 and row 2 from B which is 7 ,and do the process for all other elements . how to do this? the requried elememts are bold and underlined
any help will be really appriciated.........thanks in advance

댓글 수: 2

madhan ravi
madhan ravi 2018년 12월 13일
Dude just give the example of your desired output
Farman Shah
Farman Shah 2018년 12월 13일
편집: Farman Shah 2018년 12월 13일
[9,7,1,4,3] is the disired output. which is underlined also

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 13일

0 개 추천

B(sub2ind( size(B), 1:length(A), A))

댓글 수: 3

Farman Shah
Farman Shah 2018년 12월 13일
Error using sub2ind (line 47)
The subscript vectors must all be of the same size.
Error in takeprobe (line 6)
res= B(sub2ind( size(B), 1:length(A), A));
return this error. I have my A data in one Coulmn and B data in 5 Columns
B(sub2ind( size(B), (1:length(A)).', A(:)))
The above will work regardless of whether A is a row or column vector. However, it will return a column of results either way. If you need a row of results, put .' at the end:
B(sub2ind( size(B), (1:length(A)).', A(:))).'
Farman Shah
Farman Shah 2018년 12월 13일
thank you very much sir.. you made my day easy.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2018년 12월 13일

댓글:

2018년 12월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by