Problem in working with ismembertol
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I have a question regarding matching numbers. My text file contains a column vector and I want to match the values in this column vector with the values that are stored in a variable in matrix form.
a = 29.8220 %(one value extracted from column vector of txt file); 3798x1 double
b = 2030x1354 double %(it contains interpolated values (in the form of floating point numbers),
% actual values were '406x270');
mask = ismembertol(a,b); %answer = 1 (means true)
problem is b not only contains 29.2880, but also "29.8219, 29.8221". I tried to look for the indices of this number and I've checked that it gave me indices of 29.8219 as well as 29.8221 along with 29.8220. For example row 1192 and column 42 returns 29.8219 and row 1231 and column 210 gives 29.8220. Kindly tell me how to solve this issue? Thank you. A picture of values in b is shown below:
[i,j] = find(abs(b-29.8220)<1e-4)
i =
1192
1231
1256
1258
1277
1283
1285
1287
1292
1295
1298
1305
1322
1329
1340
1341
1342
1348
1350
1364
1373
1379
1419
1433
1445
1464
1488
j =
42
210
345
358
472
509
522
535
566
585
604
648
750
790
849
854
859
890
899
962
998
1023
1147
1177
1204
1238
1278
1 commentaire
Walter Roberson
le 27 Sep 2021
Remember when you use ismembertol() in that form, it is looking for the elements of a anywhere in b, not just in corresponding rows or corresponding columns.
Réponses (1)
Cris LaPierre
le 27 Sep 2021
Modifié(e) : Cris LaPierre
le 27 Sep 2021
2 commentaires
Cris LaPierre
le 27 Sep 2021
Try flipping a and b.
mask = ismembertol(b, a, 1e-4);
The result will be 2030x1354.
Here's a simple example.
a=29.8220*cumsum(ones(3798,1)*.001); % 3798x1 double
b=29.8220+(rand(2030,1354)-.5)/10; % 2030x1354 double
mask=ismembertol(b,a,1e-4); % 2030x1354 logical
imagesc(mask)
Voir également
Catégories
En savoir plus sur Code Execution 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!