'Find' function working incorrectly, have tried floating point accuracy resolution

romanex

I have vertically concatenated files from my directory into a matrix that is about 60000 x 15 in size (verified).

d=dir('*.log');
n=length(d);
data=[];
for k=1:n
    data{k}=importdata(d(k).name);
end
total=[];
for k=1:n
    total=[total;data{n}];
end  

I am using a the following 32-iteration loop and the 'Find" function to locate row numbers where the final column is an integer corresponding to the integer iteration of the loop:

for i=1:32
    v=[];
    vn=[];
    [v,vn]=find(abs(fix(i)-fix(total))<eps);
    g=length(v)
end

I have tried to account for the floating point accuracy by using 'fix' on values of 'i' and values from matrix 'total', in addition to taking their absolute difference and checking it to be less than a tolerance of 'eps' (floating-point relative accuracy function), up to a tolerance of .99.

The 'Find' function is not working correctly. It is only working for certain integers (although it should be locating all of them (1-32)), and for the integers it does find the values are incomplete.

What is the problem here? If 'Find' is inadequate for this purpose, what is a suitable alternative?

Suever

You are getting a lot of zeros because you are looking not just at the 15th column of data but the entire data matrix so you are going to have a lot of non-integers.

Also, you're using fix on both numbers and since floating point errors can cause the number to be slightly above and below the desired integer, this will cause the ones that are below to round down an integer lower than what you'd expect. You should use round to round to the nearest integer instead.

Rather than using find to do this, I would use simple boolean logic to determine the value of the last column

for k = 1:32
    % Compare column 15 to the current index
    matches = abs(total(:,end) - k) < eps;

    % Do stuff with these matches
    g = sum(matches);   % Count the matches
end

Depending on what you want to actually do with the data, you may be able to use the last column as an input to accumarray to perform an operation on each group.

As a side note, you can replace the first chunk of code with

d = dir('*.log');

data = cellfun(@importdata, {d.name}, 'UniformOutput', false);
total = cat(1, data{:});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Floating point accuracy with different languages

Java Application refuses to display output as Floating Point. Have tried Casting, multiplying 1.0, adding 0.0, nothing works

how set numpy floating point accuracy?

Computing floating point accuracy (K&R 2-1)

Managing floating point accuracy

Floating point comparison not working on pandas groupby output

Strange issue with floating point accuracy on ARM64

Floating point resolution at a given number

Difference between double and float in floating point accuracy

Exact Regex expression for floating point number is not working

Floating point accuracy

floating point accuracy in MIPS assembly

Find a floating point value in a matrix

Best possible accuracy for single precision floating point division

How to change the accuracy of a floating point number in a cell in QTableWidget?

Floating point GA fitness function

comparing accuracy for calculating floating point with x*0.1 and x/10.0

Preserving Accuracy When Formatting a Floating Point Number to Display With Two-point Precison (Java)

Floating point arithmetic not working as expected

Find floating point accuracy

Groovy vs Java - difference in floating point accuracy

I have tried to write a code to find if a word is a palindrome or not but it is not working. Whats's wrong with it?

How to increase accuracy of floating point second derivative calculation?

friend, i have tried to insert data from a HTML form into a Mysql database but it's not working, also unable to find the error

Find a real life example of floating point error

Find floating-point numbers

What domain does the Perl floating point have?

Accuracy of floating point calculations: is something converting rational -> double-float?

Elixir floating point division accuracy