Compair two vectors with different length and different values??

Hallo
Lets say i have two vectors A, B with different length (Length(A) not equal to Length(B)) and the Values in Vector A, are not the same as in Vector B. i want to compair each value of B with Values of A (Compair means if Value B(i) is alomst the same value of A(1:end) for example B(i)-Tolerance<A(i)<B(i)+Tolerance.
How Can i do this without using For loop as the data are huge?
I know ismember, intersect,repmat,find but non of those function can really help me

2 commentaires

Huge is relative ... How would you do this using a for-loop? It might be easy to improve upon that.
What is it exactly you want to know. Your wordings suggest that you only want to see if an element of B is close one (or more) elements of A, while your formula suggests that you want it the other way around ...
Aubai
Aubai le 12 Juil 2013
Modifié(e) : Aubai le 12 Juil 2013
So i have a wt Values (on Y-axie) of one signal with Sampling frequency of F1, B Matris is 594301*1 double and the second matrix is also a wt Values (on Y-axie) with Sampling frequency of F2, A Matris is 713164*1 double. there is a time shift between the two wt function that i would like to calculate. for that i am trying to find the equality values of B Matrix with A Matrix (Like resample) and then getting the index of those A values equale to the B values in order to get the X- axie corresponding values (time) and finaly calcualte the time difference. with for i did it as the following:
A = Angle_Measured_OMERCON;
B = TTy;
RESULTS = [];
for i = 1: length(A)
for j = 1:length(B)
if A(i) == B(j)
Results(i,j) = i;
elseif B(j)-1 < A(i) < B(j)+1
Results(i,j) = i;
end
end
end
end

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 12 Juil 2013
This is a job for Bruno's FEX: ismemberf.

5 commentaires

the ismemberf is not exactly what i am looking for as i would like to have an output as following: Matrix C contain the corresponding index values of A that equals B This means: if A is 713164*1 double and B is 594301*1 double then C would be for example 713164*594301 double
A [713164x594301] double matrix requires 3'390'672'626'912 Bytes, which are 3.4 TB. Considering the massive redundancy of this matrix it would be unefficient to buy a large computer cluster to carry such a huge array. Therefore I'm convinced that ismemberf is the best solution and its replies, especially the 2nd output, should contain all you need.
I am trying to use this function but i am not getting the expected results can you please then help me understand this function better? So i am trying the following example:
if true
[tf, loc]=ismemberf(0.32(B), (0:0.1:1)(A),'tot',0.02)
% so i want to be able to identify the 0.3 location in (A) how can i do that with this function?
end
Thx for the support
The help section of ismemberf is actually clear.
A = 0:0.1:1
B = 0.32
[tf, loc] = ismemberf(B, A, 'tol', 0.02) % "tol", not "tot"!
Now tf is true, because B is found inside a, and loc is 4, because it is found at the 4th element of A.
Thx for the support: It seems this is how i can do it
if true
A_diff_2 = diff(A,2);
B_diff_2 = diff(B,2);
A_diff_max = max(A_diff_2);
B_diff_max = max(B_diff_2);
Zero_Crossing_Points_A = find(A_diff_2 >= 178);
First_Point_of_calculation_A = Zero_Crossing_Points_A(1);
Zero_Crossing_Points_B = find(B_diff_2 >= 359);
First_Point_of_calculation_B = Zero_Crossing_Points_B(2);
i = 1;
Delta_final_time = [];
Delta_final_Angle = [];
time_Final = [];
%------------------------ Try ------------------------------
while i<=length(Zero_Crossing_Points_B)
if i == 1395
haha = 2;
end
if i == 1
A_cut = A(i:Zero_Crossing_Points_A(i));
A_time_cut = A_time(i:Zero_Crossing_Points_A(i));
B_cut = B(i:Zero_Crossing_Points_B(i));
B_time_cut = B_time(i:Zero_Crossing_Points_B(i));
[tf, loc] = ismemberf(B_cut, A_cut, 'tol', 1);
if tf ~= 1
error('Worrning','One of the CAN values was not recognized by OMERCON values')
else
Delta = B_time_cut - A_time_cut(loc);
Delta_time = mean([A_time_cut(loc) B_time_cut]');
Delta_final_time = [Delta_final_time,Delta];
Delta_final_Angle = [((Delta*360)/0.02) ,Delta_final_Angle];
time_Final = [time_Final,Delta_time'];
%tryy(i,1:length(Delta_final_Angle)) = Delta_final_Angle(1:end);
end
else
A_cut = A(Zero_Crossing_Points_A(i-1):Zero_Crossing_Points_A(i));
A_time_cut = A_time(Zero_Crossing_Points_A(i-1):Zero_Crossing_Points_A(i));
B_cut = B(Zero_Crossing_Points_B(i-1):Zero_Crossing_Points_B(i));
B_time_cut = B_time(Zero_Crossing_Points_B(i-1):Zero_Crossing_Points_B(i));
if length(A_cut) > 200
A_cut = A_cut(2:end);
A_time_cut = A_time_cut(2:end);
end
if length(B_cut) > 17
B_cut = B_cut(2:end);
B_time_cut = B_time_cut(2:end);
end
[tf, loc] = ismemberf(B_cut, A_cut, 'tol', 1.6);
if tf ~= 1
error('Worrning','One of the CAN values was not recognized by OMERCON values')
else
Delta = B_time_cut - A_time_cut(loc);
Delta_Angle = (Delta*360)/0.02;
Delta_time = mean([A_time_cut(loc) B_time_cut]');
if length(Delta) < 17
Delta(end+1:17) = 0;
Delta_time(end+1:17) = 0;
Delta_Angle(end+1:17) = 0;
%Delta = [Delta(1:end),zeros(length(Delta)+1:17)];
Delta_final_time = [Delta_final_time,Delta];
Delta_final_Angle = [Delta_final_Angle,((Delta*360)/0.02)];
time_Final = [time_Final,Delta_time'];
%tryy(i,1:length(Delta_Angle)) = Delta_Angle(1:end);
else
Delta_final_time = [Delta_final_time,Delta];
Delta_final_Angle = [Delta_final_Angle,((Delta*360)/0.02)];
time_Final = [time_Final,Delta_time'];
%tryy(i,1:length(Delta_Angle)) = Delta_Angle(1:end);
end
end
end
i = i + 1;
end
Delta_N_Loc = find(Delta_final_Angle < 0);
Delta_N_Loc_New = Delta_N_Loc + 1;
Delta_final_Angle(Delta_final_Angle < 0) = Delta_final_Angle(Delta_N_Loc_New);
time_Zeros = find(time_Final == 0);
time_Zeros_P_1 = time_Zeros + 1;
time_Zeros_N_1 = time_Zeros - 1;
time_Final(time_Final == 0) = ((time_Final(time_Zeros_N_1))+(time_Final(time_Zeros_P_1)))/2;
Delta_final_Angle_Zeros = find(Delta_final_Angle == 0);
Delta_final_Angle_Zeros_P_1 = Delta_final_Angle_Zeros + 1;
Delta_final_Angle_Zeros_N_1 = Delta_final_Angle_Zeros - 1;
Delta_final_Angle(Delta_final_Angle == 0) = ((Delta_final_Angle(Delta_final_Angle_Zeros_N_1))+(Delta_final_Angle(Delta_final_Angle_Zeros_P_1)))/2;
Delta_final_Angle_Round = round(Delta_final_Angle);
time_Final_r = reshape(time_Final,numel(time_Final),1);
Delta_final_Angle_r = reshape(Delta_final_Angle_Round,numel(Delta_final_Angle_Round),1);
if length(Delta_final_Angle_r) > length(time_Final_r)
Delta_final_Angle_r = Delta_final_Angle_r(1:length(time_Final_r));
end
end

Connectez-vous pour commenter.

Plus de réponses (1)

A = randi(25,10,1);
B = randi(30,20,1);
tolerance = 1;
out = abs(bsxfun(@minus,B(:),A(:).')) < tolerance;

2 commentaires

Aubai
Aubai le 12 Juil 2013
Modifié(e) : Aubai le 12 Juil 2013
Thanks for the fast replay i am now getting an out of memory error when perofrming this type of operation!! how can i over come that. note: A (713164*1 double) B (594301*1 double)
Easy get a computer with extra memory !!!!!!!! cheers

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by