find index of a matrix through another matrix

1 回表示 (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 21 日
I have this matrix A = [1 3 4 6 7] and B = [3 4] that it's a subset of A matrix. For example I would find the index of B matrix through A matrix. Having 3 as number I would know the index of 3 in matrix B.How can I do?

回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
編集済み: Azzi Abdelmalek 2012 年 9 月 21 日
B = [3 4]
idx=find(B==3)
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
you have asked about index in B , what about A?
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 21 日
Because in my scripts I don't have directly A matrix.This is an example that permitted me to understand how find works.

サインインしてコメントする。


per isakson
per isakson 2012 年 9 月 21 日
編集済み: per isakson 2012 年 9 月 21 日
This is possible if A and B are whole numbers
A = [ 1, 3, 4, 6, 7 ];
B = [ 3, 4 ];
ix1 = strfind( A, B );
ix2 = ix1 + numel(B) - 1;
all( B == A(ix1:ix2) )
If I understood you correct

Image Analyst
Image Analyst 2012 年 9 月 21 日
Actually I thought first that what you meant was what per answered, but then I read your response to Azzi. I'm not sure you worded this correctly but when Azzi asked about it, you seemed to indicate it was worded exactly as you wanted. So in that case, I guess that would mean that if B is in A, the index of B (and you did say in B, not A) would always be 1. If B is not in A then there is no solution - obviously since B is not in A.

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by