Effacer les filtres
Effacer les filtres

Find function not working when trying to look for a big number

4 vues (au cours des 30 derniers jours)
Rajesh
Rajesh le 26 Nov 2012
Hello everyone, I have 2 matrices with the first column in each matrix which has the key records which link both the matrices. I'm trying to take "M_rec_qty_1" as my base matrix and trying to use the find function to check the records from each row in the first column to be present in the first column of "final_matrix".
If i find it, then i insert the row number, column number and the data i found in to one more matrix "pos_data_matrix", for further use in the code.
But the problem seems to be that the data i'm looking in final_matrix is really big.. for example... "5642007779", so when find tries to use this data it converts it into 5.642 * 10^9 and hence is not able to find an exact match and brings more vales in the same range. because of which the logic doesn't work. Can someone please help solving this issue.
Please find the for loop which i sue in the code below.
for m1r = 4:1000
[rownum,colnum] = find(final_matrix==M_rec_qty_1(m1r,1))
pos_data_matrix(m1r-3,1) = rownum;
pos_data_matrix(m1r-3,2) = colnum;
pos_data_matrix(m1r-3,3) = M_rec_qty_1(m1r,1);
endfor
Thanks Raj
  3 commentaires
Rajesh
Rajesh le 26 Nov 2012
Hello Daniel, The numer are whole numbers... there are no decimal points... the problem comes when it tries to compare lets say 5642007779 and 5642007780.... because it changes it into 5.64*10^9 for both cases... it assumes the data is equal.
Daniel Shub
Daniel Shub le 26 Nov 2012
Are you sure? I get not equal with
x = 5642007779;
y = 5642007780;
isequal(x, y)

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 26 Nov 2012
5642007779 is not "large". The output "5.642 * 10^9" appears in the command window, but the internal storage is not affected. Try: "format long g" to influence the output in the command window. Further explanations can be found by: doc format

Plus de réponses (1)

Andreas Goser
Andreas Goser le 26 Nov 2012
Depending on your application you can work with INTEGER data types or work with comparing "between x-phi and x+phi boundaries".
  3 commentaires
Andreas Goser
Andreas Goser le 26 Nov 2012
Your profile is empty. I think it depends on what your situation is. Are you a computer science student? then you really should try to understand the underlying fundamentals of this behaviour. Are you are biologist researcher? Then you probably just need a solution without understanding each detail. But then we would a fully example inclusing data and not just a code fragement.
Rajesh
Rajesh le 26 Nov 2012
Hello Andreas, sorry that i havent updated my profile yet.. i will update it soon..... but i had a problem with only formatting the output. as mentioned by Jan. Thank you very much for the response.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by