从文件加载时 Octave 无法识别值
我有一个制表符分隔值文件,我加载该文件并将其转换为 tablicious 表,其中值是标量。 从表中选取值时,它无法识别所有值。如果我直接创建与矩阵完全相同的值,它就会这样做。(tab1.a == tab2.a)'
给出 ans = 1 1 0 0 0 0 1
显示值 3 到 6 不同。 2.2204e-16
的差异表明这是一个数字精度问题,但我该如何允许这一点呢? 我使用的是 Octave 版本 6.4.0
clear all; clc;
pkg load tablicious
function pick = tabpick(tab, a, b);
pick = ((tab.a==a) & (tab.b==b));
if ~sum(pick) % no match
error("Selection not dataset !!\n");
endif
pick = table2struct( tab(pick,:));
return
endfunction
% create table direct
m = [ 1.315 1.7
1.315 2.19
1.66 2.1
1.66 2.3
1.66 3.03
1.76 3.28
1.9 2.4 ];
a = m(:,1);
b = m(:,2);
tab1 = table(a, b);
% prettyprint the table
pp(tab1)
% show type of variables
typeinfo(tab1.a), typeinfo(tab1.a(1))
% load table from tsv file
fid = fopen('table_test.txt', 'r');
tab_file = textscan(fid,"%f %f",'delimiter','\t', 'Headerlines',1);
a = tab_file{1};
b = tab_file{2};
tab2 = table(a, b);
pp(tab2)
typeinfo(tab2.a), typeinfo(tab2.a(1))
% compare the two: They are different !
(tab1.a == tab2.a)'
% we can pick any value by menu
pick=menu('pick b', cellstr(num2str(tab2.b)));
table2struct( tab2(pick,:))
% pick from tab1 works fine
tabpick(tab1, 1.315, 2.19)
tabpick(tab1, 1.76, 3.28)
% pick from tab2 fails on second one
tabpick(tab2, 1.315, 2.19)
tabpick(tab2, 1.76, 3.28)
I have a tab separated values file which I load and convert to a tablicious table where the values are scalars.
When picking values from the table it does not recognize all values. If I create the exact same values direct as a matrix it does.(tab1.a == tab2.a)'
gives ans = 1 1 0 0 0 0 1
showing that values 3 to 6 are different. Difference of 2.2204e-16
indicates it's a numeric accuracy thing, but how can I allow for that?
I'm on Octave version 6.4.0
clear all; clc;
pkg load tablicious
function pick = tabpick(tab, a, b);
pick = ((tab.a==a) & (tab.b==b));
if ~sum(pick) % no match
error("Selection not dataset !!\n");
endif
pick = table2struct( tab(pick,:));
return
endfunction
% create table direct
m = [ 1.315 1.7
1.315 2.19
1.66 2.1
1.66 2.3
1.66 3.03
1.76 3.28
1.9 2.4 ];
a = m(:,1);
b = m(:,2);
tab1 = table(a, b);
% prettyprint the table
pp(tab1)
% show type of variables
typeinfo(tab1.a), typeinfo(tab1.a(1))
% load table from tsv file
fid = fopen('table_test.txt', 'r');
tab_file = textscan(fid,"%f %f",'delimiter','\t', 'Headerlines',1);
a = tab_file{1};
b = tab_file{2};
tab2 = table(a, b);
pp(tab2)
typeinfo(tab2.a), typeinfo(tab2.a(1))
% compare the two: They are different !
(tab1.a == tab2.a)'
% we can pick any value by menu
pick=menu('pick b', cellstr(num2str(tab2.b)));
table2struct( tab2(pick,:))
% pick from tab1 works fine
tabpick(tab1, 1.315, 2.19)
tabpick(tab1, 1.76, 3.28)
% pick from tab2 fails on second one
tabpick(tab2, 1.315, 2.19)
tabpick(tab2, 1.76, 3.28)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
差值给出了线索。与...一起工作
The difference value gave the clue. Working with