The floating point error exists in both linspace and array creation if the increment is not an integer value. Intersect and ismember fails.
Show older comments
clc;
clear all;
A=round(345684*rand(3000,100,10))/1000;
pmn_inc=0.0001;
pmn_saved=linspace(pmn_inc,500,500/pmn_inc);
% pmn_saved is all possible combinations of numbers
% with 0.0001 accuracy ranging from
% 0.0001 to 500
[Cval,ia,ic]=unique(A); % have determined unique values of A
% -> 3 decimal spaced values -> maximum value:345.6840
[C2,Ipmn,ICval]=intersect(pmn_saved',Cval);
% length of C2 is not equal to Cval
C1=pmn_saved(Ipmn)';
2 Comments
KSSV
on 27 Jul 2018
What do you mean by not working? Error? What is the problem?
"Why does intersect function not work "
How are you checking this? Are you comparing floating point values?
"The floating point error exists in both linspace and array creation if the increment is a decimal value."
Not always, as there are plenty of decimal numbers that can be represented exactly by binary floating point numbers. Try starting from an integer and incrementing by 0.5 or 0.25: no floating point error!
"Intersect and ismember fails."
No, they don't fail. You are comparing different values, which means that ismember and intersect correctly identify them as being different values. Nothing fails.
Accepted Answer
More Answers (1)
Richards Stanislaus
on 27 Jul 2018
0 votes
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!