Compare values in array1 with array2 and store a new value in a new array if match found
이전 댓글 표시
I have a problem of comparing two arrays on Matlab scripting and below I have explained.
%Array1 has one column
Array1=[1.56357468109619
1.61046126078761
1.81562025010618
1.68554263182706
2.01705143067582
2.20087755213663
1.90411420706440
1.86094752726691
1.92177045043986
1.78486562784988
1.85660250759791
1.53693897473804
2.01744530015071
1.90897780937155]
%Array2 has two columns
Array2=
2.02888000000000 600;
1.80918000000000 500;
1.65728000000000 400;
1.52849000000000 300;
1.35517000000000 200;
1.13304000000000 100;
1.00398000000000 0
I want to compare each value of the single column in Array1 with the values in column 1 of Array2. If the value of Array1 matches or fits within a range or within a given limit range with a value in column1 of Array2, I wish to create a new array (Array3) with the corresponding value in Column2 of Array2.
Example: 1st value in column1 of Array1 = 1.61046126078761 Since this value is closest to 3rd value of column1 in Array2, I want to assign the first value in Array3 as 400. Likewise I want to check all the values in Array1 and assign the values and create the new Array3
Would be great if someone could help me out! Thanks in advance!
Best wishes Sarala
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2017년 6월 29일
편집: Andrei Bobrov
2017년 6월 30일
A = sortrows(Array2,1);
out = A(discretize(Array1,[-inf;A(1:end-1,1)+diff(A(:,1))/2;inf]),2);
카테고리
도움말 센터 및 File Exchange에서 Data Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!