필터 지우기
필터 지우기

How to match array data and excel data?

조회 수: 3 (최근 30일)
Nilna Almumtazah
Nilna Almumtazah 2022년 12월 19일
댓글: Nilna Almumtazah 2022년 12월 23일
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
Nilna Almumtazah
Nilna Almumtazah 2022년 12월 20일
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 2022년 12월 20일
I want to retrieve the row number, provided that the column value matches data 'I'.

댓글을 달려면 로그인하십시오.

답변 (1개)

prasanth s
prasanth s 2022년 12월 20일
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
Adam Danz
Adam Danz 2022년 12월 20일
@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 2022년 12월 23일
OK, thanks for both of your answers

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by