Problem in working with ismembertol

4 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2021-9-27
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.

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
Cris LaPierre 2021-9-27
编辑:Cris LaPierre 2021-9-27
LIA = ismembertol(A,B) uses a default tolerance of 1e-6 for single-precision inputs and 1e-12 for double-precision inputs.
Try using this syntax instead:
a = 29.8220;
ismembertol(a,29.8219)
ans = logical
0
ismembertol(a,29.8219,1e-4)
ans = logical
1
  2 个评论
Zhou Ci
Zhou Ci 2021-9-27
It still gave me same result. I used this line:
% a = 3789x1 double;
% b = 2030x1354 double;
mask = ismembertol(a, b, 1e-4);
ans
=3789x1 logical % (all are true (means 1))
Cris LaPierre
Cris LaPierre 2021-9-27
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)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Code Execution 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by