Having trouble getting this find work properly

I have two cell arrays where the first one is time converted into serial date and the second cell array (bb) which has specific times associated with other data in it. I'm trying to extract the rows in bb in chronological order by using time cell array. BB cell array is a 1x34 cell array where each cell once expanded is a nx7 array.
I am rather new at this, but I came up with this, and I can't get this working correctly as well as do what I want it to do. Not even sure if it is in the right direction.
I'm trying to find the serial date in the test1 file in all columns of bb (1x34) and extract it into another matrix when I call the first row of time (test1). BB's {1x34}(nx7) the column 7 of the nx7 is the serial date for that BB.
for i=1:length(test1)
for t=1:length(bb)
for w=1:length(bb{t})
[a{t} b(w,1:7)]=find(bb{t}(w,1:7)==test1(i)
end
end
end

Réponses (1)

KSSV
KSSV le 20 Déc 2016

0 votes

don't use find, check with ismemebr, ismemebrtol.

6 commentaires

liu James
liu James le 20 Déc 2016
Modifié(e) : liu James le 20 Déc 2016
Hey KSSV I've tried it with ismember and it's still not correct.
for i=1:length(test1)
for t=1:length(bb)
for w=1:length(bb{t})
[a b]=ismember(bb{t}(w),test1(i));
end
end
end
clc; clear
load bb.mat ;
load test1.mat ;
for i=1:length(test1)
for t=1:length(bb)
for w=1:length(bb{t})
[aa1, bb1]=find(bb{t}(w,:)==test1(i))
if ~isempty(aa1)
a{t} = aa1 ; b(w,1:7) = bb1 ;
end
end
end
end
Takes hell lot of time and no values I can find common.
liu James
liu James le 20 Déc 2016
Shouldn't be. Under Test1 row 589 for example provides time series number 735028, while bb{1}{1,7} is also 735028.
If that's the case, test1(589)-bb{1}{1,7} should be exactly equal to 0. From what you've said it will not be exactly 0 but will be a nonzero value with very small magnitude.
The == operator performs exact, down-to-the-last-bit equality testing. This means that two numbers that look the same may not be the same.
format short
x = 1.25
y = x+eps(x)
areTheyEqual = x == y % false
howDifferentAreThey = y-x % small
If you want to confirm that x and y are not the same, display their hex pattern.
format hex
x
y
format % reset the display format to default
If I'm understood what you said, the find will not extract it because of the extra decimals even though they are 0 is that correct? However, if I type this
[a b]=find(test1(589)==bb{1}(1,7))
a =
1.00
b =
1.00
it will show that there is a position vs empty matrix.
[a b]=find(test1(590)==bb{1}(1,7))
a =
[]
b =
[]
You fix a small parameter eps and subtract them.
eps = 10^-6 ;
idx = test1(589)-bb{1}(1,:)<eps
so in idx if any value is 1, then you can say they are equal. Using == for flottant numbers is not advisable. Also, I suggested you to use ismembertol.

Connectez-vous pour commenter.

Question posée :

le 20 Déc 2016

Commenté :

le 21 Déc 2016

Community Treasure Hunt

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

Start Hunting!

Translated by