"Diogo Londero da Silva" <diogolondero@yahoo.com.br> wrote in message <iargsc$8fv$1@fred.mathworks.com>...
> Hi,
>
> I would like to compare the elements of two diferent matrixes (A and B), related by the first colum, that in my case represents the time. The matrixes always have the same number of columns but different numbers of rows. In adittion, the numbers in the frist column are close, but not identical. For example:
>
> A=[ 1 2
> 5 4
> 7 6]
>
> B=[1.5 2.1
> 3.2 3.1
> 4.9 4.1
> 6.7 7]
>
> To compare the second row of matrix A ( A(2,1)=5) , how can I find the index of the correspondent time in matrix B? In this case, the answere will be B(3,1)=4.9, which is the closest number to 5.
>
> Many thanks, Diogo.
So for every element in A, you want to know the closest element in B?
%Data
A=[ 1 2;5 4 ;7 6]
B=[1.5 2.1
3.2 3.1
4.9 4.1
6.7 7]
%Engine
[~,idx] = min(bsxfun(@(x,y)(abs(xy)),A(:),B(:).'),[],2);
reshape(B(idx),size(A))
