# How to identify a particular range of y values corresponding to a specif range of x

3 views (last 30 days)
navan on 21 Jul 2015
Commented: Star Strider on 21 Jul 2015
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

Star Strider on 21 Jul 2015
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 CommentsShowHide 1 older comment
Star Strider on 21 Jul 2015
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.