How to identify a particular range of y values corresponding to a specif range of x
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a matrix A=[1 2 3, 4 5 6, 7 8 9] and a corresponding matrix B=[11 12 13, 14 15 16, 17 18 19]. i want to find out a range of B values corresponding to matrix A. for example:
For A1=[1 4 7] corresponding B1=[11 14 17] and for A2=[2 6 8] corresponding B2=[ 12 15 18]
how can i do that
댓글 수: 0
답변 (1개)
Star Strider
2015년 7월 21일
First, I believe you intend to replace the commas in ‘A’ and ‘B’ with semicolons. After that, you simply do matrix addressing:
A=[1 2 3; 4 5 6; 7 8 9];
B=[11 12 13; 14 15 16; 17 18 19];
A1 = A(:,1)
B1 = B(:,1)
A2 = A(:,2)
B2 = B(:,2)
A1 =
1
4
7
B1 =
11
14
17
A2 =
2
5
8
B2 =
12
15
18
댓글 수: 2
Star Strider
2015년 7월 21일
I am not sure what you want to do.
Experiment with the matrix indexing I outlined earlier. See the documentation on Matrices and Arrays for a full description of array indexing.
If you want to get the corresponding indices of specific unique values in ‘A’ and get the elements with corresponding indices in ‘B’, you can do something like this:
A1idx = find((A == 1) | (A == 4));
B1 = B(ind2sub(size(A), A1idx))
B1 =
11
14
I will leave it to you to read the documentation on ind2sub and experiment with the code.
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!