Effacer les filtres
Effacer les filtres

How to find out index number bewteen two arrays

3 vues (au cours des 30 derniers jours)
AS
AS le 15 Avr 2020
Modifié(e) : Stephen23 le 15 Avr 2020
I have two matrices with different columns number and single row: A=[ 11.6 56.9 30.5 80 34 78.98 34.01 3 1.5] and B=[56.9 1.5 3 30.5]. Now I want to find out the index number of matrix B in matrix A i.e. find out the row and column number of the numberical values of matrix B in matrix A. Also want to generate I new matrix where these row and columns number will be stored and rest of the values will be 1.
Example:
A=[ 11.6 56.9 30.5 80 34 78.98 34.01 3 1.5]
B=[56.9 1.5 3 30.5]
M=[1 1 1 1 1 1 1 1 1];
New_M=[1 56.9 30.5 1 1 1 1 3 1.5]

Réponse acceptée

Stephen23
Stephen23 le 15 Avr 2020
Modifié(e) : Stephen23 le 15 Avr 2020
You could use ismembertol like this:
>> A = [11.6,56.9,30.5,80,34,78.98,34.01,3,1.5];
>> B = [56.9,1.5,3,30.5];
>> [X,Y] = ismembertol(A,B);
>> M = ones(size(A));
>> M(X) = B(Y(X))
M =
1 56.9 30.5 1 1 1 1 3 1.5

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by