Cross correlating matrix for each column

Hy all, i am a beginer in matlab. I have some problem with cross corelating two matricces, because i have large number of data, i have made a loop model like this:
Load a.dat
Load b.dat
X1=a(:,m)
X2=b(:,m)
For m=1:2;
X=xcorr(x1,x2)
End
Plot(x)
But the answer is undefined variable "m". a & b is a 34x34 matrix,

2 comentarios

Hi
When you include code in your answer, try to use the "code" block (button at the top), it makes it more readable.
So, just repeating your code with some line numbers:
1 Load a.dat
2 Load b.dat
3 X1=a(:,m)
4 X2=b(:,m)
5 for m=1:2;
6 X=xcorr(x1,x2)
7 End Plot(x)
In lines 3 and 4, you are calling a(:,m) and b(:,m), but m is only defined in line 5. See the problem? You need to define m before you use it. Also, be aware that matlab is case-sensitive!
What are you trying to plot? The crosscorrelation of each column of a with each column of b? That's going to be a huge number of lines...
La Ode Marzujriban
La Ode Marzujriban el 22 de En. de 2015
Thank you for your answer mr.ced I have recode these into: load a.dat load b.dat m = 1:34 x1 = a(:,m) X2 = b(:,m) For m=1:34 x = xxorr(x1,x2) End
Ya i want to plot each result when x is a distance, y is a time and the amplitde as the result of cross corelation of each column

Iniciar sesión para comentar.

Respuestas (1)

dpb
dpb el 21 de En. de 2015
Editada: dpb el 22 de En. de 2015
help xcorr
...
xcorr(A), when A is an M-by-N matrix, is a large matrix with
2*M-1 rows whose N^2 columns contain the cross-correlation
sequences for all combinations of the columns of A.
...
So,
X=xcorr([a b]);
but, as ced notes,
size(X) = [2*68-1,34^2]
= [135,1156]
ADDENDUM
Yeah, sorry, I wasn't thinking about it producing the self correlation vectors, too...
[M,N]=size(x,2);
X=zeros(2*M-1,N*N);
k=0;
for i=1:N
for j=1:N
k=k+1;
X(:,k)=xcorr(x(:,i),y(:,j));
end
end

2 comentarios

Ced
Ced el 21 de En. de 2015
Yep. That's a bit of an overestimate however, since with xcorr([a b]) you are computing the autocorrelations of A and B too and each crosscorrelation twice.
La Ode Marzujriban
La Ode Marzujriban el 22 de En. de 2015
Yes its look over, i need just the result of each column, do you have any idea? Because i have try like my mention in mr.ced answer but the result is (x2 must be a vector (min(size(b))==1)

Iniciar sesión para comentar.

Preguntada:

el 21 de En. de 2015

Editada:

dpb
el 22 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by