フィルターのクリア

Represent results in vector format.

10 ビュー (過去 30 日間)
Ricardo Gutierrez
Ricardo Gutierrez 2019 年 10 月 8 日
コメント済み: Ricardo Gutierrez 2019 年 10 月 8 日
Hi. Good morning.
I hope you can help me.
I have two matrices A and B it is about finding the positions of the values ​​of the matrix A in the mariz B.
The code below finds the values ​​in matrix A and their respective positions and values ​​in matrix B
______________________________________
clc; clear; close all; short format
A = [1 2 3 4 5 6 7 8 9 10];
B = [1 25 31 41 11 61 7 81 31 11
   81 3 71 31 31 6 11 8 61 31
   21 81 2 61 5 31 31 31 19 12
   91 31 41 4 61 81 61 41 10 9];
for b = 1: 1: length (A)
E = A (1, b)
[row1, col1] = find (B == E)
end
______________________________
The results shown in the command window are in this format. I show only one value found:
_______________________________________________
E =
    10
row1 =
     4
col1 =
     9
_________________________________________
I would like to know how to do it to show me three vectors, a vector of values, one of rows and another of columns for example:
      E = [1 2 3 4 5 6 7 8 9 10]
row1 = [1 3 2 4 3 2 1 2 4 4]
 col1 = [1 3 2 4 5 6 7 8 10 9]
I await your advice.
Thanks and regards.

採用された回答

Stephen23
Stephen23 2019 年 10 月 8 日
>> A = 1:10
A =
1 2 3 4 5 6 7 8 9 10
>> B = [1,25,31,41,11,61,7,81,31,11;81,3,71,31,31,6,11,8,61,31;21,81,2,61,5,31,31,31,19,12;91,31,41,4,61,81,61,41,10,9]
B =
1 25 31 41 11 61 7 81 31 11
81 3 71 31 31 6 11 8 61 31
21 81 2 61 5 31 31 31 19 12
91 31 41 4 61 81 61 41 10 9
>> [X,Y] = ismember(A,B);
>> E = A(X)
E =
1 2 3 4 5 6 7 8 9 10
>> [R,C] = ind2sub(size(B),Y(X))
R =
1 3 2 4 3 2 1 2 4 4
C =
1 3 2 4 5 6 7 8 10 9
  1 件のコメント
Ricardo Gutierrez
Ricardo Gutierrez 2019 年 10 月 8 日
Excellent !!!
It works !!!
Thanks so much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by