Line, column, and value in matrix B of repeated values ​​in A.

1 回表示 (過去 30 日間)
Ricardo Gutierrez
Ricardo Gutierrez 2019 年 11 月 7 日
コメント済み: Ricardo Gutierrez 2019 年 11 月 8 日
Hi. Good day.
I have a code that indicates line, column and value in matrix B, which are in vector A.
But this code does not allow me to have repeated values ​​in matrix B, which is already in vector A
% ________________________________
clc; clear; close all; format short;
A = [10 8 8 6 2];
 B = [10 12 16 15 11
       8 16 21 6 26
       85 61 21 48 11
       41 52 62 44 2
       29 51 55 59 16
       98 95 93 92 99];
  
for b = 1: 1: 5
     Value (b) = A (1, b);
     [row (b), col (b)] = find (B == Value (b));
end
Value
row
col
=========================================
Command Window
Value =
    10 8 8 6 2
row =
     1 2 2 2 4
col =
     1 1 1 4 5
===========================================
What do I have to do to make the code detect the position of repeated values ​​in matrix B
Something like that:
A = [10 8 8 6 2];
 
B = [10 12 16 15 11
     8 16 21 6 26
     8 61 21 48 11
     41 52 62 44 2
     29 51 55 59 16
     98 95 93 92 99];
Command Window
Value =
    10 8 8 6 2
row =
     1 2 3 2 4
col =
     1 1 1 4 5
----------------------------
Hoping you can help me.
Thank you.
  2 件のコメント
per isakson
per isakson 2019 年 11 月 7 日
Is it true that
  • a value that is repeated in A must be repeated the same number of times in B ?
  • repeated values in A are consecutive
Ricardo Gutierrez
Ricardo Gutierrez 2019 年 11 月 8 日
A value that is repeated in A must be repeated the same number of times in B? ==== Yes
Repeated values in A are consecutive ===== Yes
In fact the vector A by a mathematical process was formed by data of the matrix B therefore the values in A must be in B.

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

採用された回答

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019 年 11 月 8 日
solution :
[row,col]=find(ismember(B,A))

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by