Compare two matrix in matlab
이전 댓글 표시
I have two matrix data1 and data2. I want to select all rows in data1 that close or equals to data2. I know that loop each element can work but it will take a long time. Is there any easy method I can use?
data1 is attached and data 2 is the following function.
x1 = (0:1:414194)';
data2 = 6*x1;
Thank a lot,
MCC
댓글 수: 1
SALAH ALRABEEI
2021년 6월 15일
what is the matrices size of data1 and data2!
채택된 답변
추가 답변 (1개)
Sulaymon Eshkabilov
2021년 6월 15일
Easy and fast efficient solution is Logical Indexing, e.g.:
IND = Data1==Data2
D1 = Data1(IND);
D2 = Data2(IND);
You can also employ round() fcn to reduce the small differences in values of the two data sets.
Or even better to compute the min. differences and get those indices, e.g.:
[minVal,ClosestIND] = min(abs(Data1-Data2))
D1 = Data1(ClosestIND);
D2 = Data2(ClosestIND);
댓글 수: 3
MCC
2021년 6월 15일
Sulaymon Eshkabilov
2021년 6월 15일
In that case, probably a loop would be an opt.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!