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!