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

2 ビュー (過去 30 日間)
navan
navan 2015 年 7 月 21 日
コメント済み: Star Strider 2015 年 7 月 21 日
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

回答 (1 件)

Star Strider
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 件のコメント
navan
navan 2015 年 7 月 21 日
Dear Strider,
Thanks a lot for your answer. But i exactly needed it to be done in a different way. 1) i want to identify B matrix corresponds to matrix A.(not necessary a full collumn) for example.
A1=[1 4] should fetch an answer B1=[11 14]
2) when it should work for a selected array of A values. how can i use it
example : A1= [1 2 3, 4 5 6] should fetch an answer B1=[11 12 13, 14 15 16]
Star Strider
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 ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by