How to match array data and excel data?

I have array data and excel data. I want to match my array data with excel data. For example, I want array data 'I' to match with excel data 'B'. If all contents of data 'I' match all columns in a particular row of data 'B', then the output result is data 'A' in the same row as data 'B'. I will be appreciated if someone guides me. Thank you
I = [0.0673 22.8800 4.5213e+03 2.1387e+03 12.4245 0.6936 3.7715 0.0474 0.2561 16.0428 82.6339];
Data 'B'
Data 'A'

5 comentarios

Adam Danz
Adam Danz el 19 de Dic. de 2022
Your text describes matching columns but your images and your example show matching rows. I'll assume you meant rows.
  1. Use readmatrix to read in your data since it appears that you are matching rows and your data appear to be homogenous, all numeric. You'll read in the two data sets as two separate matrix variables.
  2. It looks like your data do not have more than 7 decimal places so roundoff error shouldn't be a problem. If it turns out that your data are more decimal places that what appears in your screenshots, you'll need to decide how you deal with precision issues that may arise. Let's cross that bridge if we come to it.
This is where I get lost in your description. Are you asking whether the selected row of A exactly matches the selected row of B or are you asking whether both rows have the same values but perhaps in different orders? Or are you asking something else?
Nilna Almumtazah
Nilna Almumtazah el 19 de Dic. de 2022
No, I want to match the contents of data 'I' with the contents of data 'B'. In the sense that all contents of data 'I' must be the same as all columns in data 'B'. After a row is found stating that the contents of all columns are the same as data 'I', then the value of that row will be used to call data in data 'A'.
Adam Danz
Adam Danz el 19 de Dic. de 2022
> all contents of data 'I' must be the same as all columns in data 'B'.
From what I understand, data I is a row vector and data B is a matrix with many rows. It is not clear to me how a row vector can be the same as a multi-row matrix.
Perhaps you could give a small example. I still do not understand your goal.
Nilna Almumtazah
Nilna Almumtazah el 20 de Dic. de 2022
For example, in data 'I', the contents are the same as data 'B' in row 9. So that the results of data 'A' in row 9 will also be obtained.
Nilna Almumtazah
Nilna Almumtazah el 20 de Dic. de 2022
I want to retrieve the row number, provided that the column value matches data 'I'.

Iniciar sesión para comentar.

Respuestas (1)

prasanth s
prasanth s el 20 de Dic. de 2022
if all data type is in array type,
the matching row positions can be obtained using
rows=all(B==I,2)
contents from 'A' obtained using
data=A(rows,:);

4 comentarios

Nilna Almumtazah
Nilna Almumtazah el 20 de Dic. de 2022
I have tried but the result is empty 0x11
prasanth s
prasanth s el 20 de Dic. de 2022
Maybe values in 'I' is different. Try I=B(9,:)
@Nilna Almumtazah, this is either because row I does not have a match in matrix B or it could be due to roundoff error as I mentioned in my initial comment under your question.
@prasanth s' answer works well for integers or for floating point decimals with low precision (few decimal places). But since it only looks for exact matches, it will not handle roundoff error gracefully.
Here's how to apply a tolerance to the comparison:
% M is the matrix
% v is the row vector
rows=all(abs(M-v)<eps(min([M(:);v(:)])),2);
data=M(rows,:);
Nilna Almumtazah
Nilna Almumtazah el 23 de Dic. de 2022
OK, thanks for both of your answers

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 19 de Dic. de 2022

Comentada:

el 23 de Dic. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by