ehensens
asked on
Problem computing array, ??? Error using ==> times Matrix dimensions must agree
Hi all,
I am having a problem computing a 1 dimensional matrix, whose elements are made up of sums of one 1-dimensional matrix dot multiplied by one column of a 2-dimensional matrix. Please see the code snippet if this sounds confusing. Why am I getting this error,
??? Error using ==> times
Matrix dimensions must agree
Error in ==> ncorr2 at 11
corr(m)=sum(a.*b(:,m))
Keep in mind that I would call this function like so:
x1 = [1;2;3]
x2 = [4;5;6]
[corr, lags] = ncorr2(x1,x2)
Thanks for all of your help and let me know if I need to be more specific or add any information!
I am having a problem computing a 1 dimensional matrix, whose elements are made up of sums of one 1-dimensional matrix dot multiplied by one column of a 2-dimensional matrix. Please see the code snippet if this sounds confusing. Why am I getting this error,
??? Error using ==> times
Matrix dimensions must agree
Error in ==> ncorr2 at 11
corr(m)=sum(a.*b(:,m))
Keep in mind that I would call this function like so:
x1 = [1;2;3]
x2 = [4;5;6]
[corr, lags] = ncorr2(x1,x2)
Thanks for all of your help and let me know if I need to be more specific or add any information!
function [corr, lags] = ncorr2(x1, x2)
[N,M]=size(x1);
d=1:(2*N-1);
lags(d)=d-N;
a=[zeros(N-1,1);x1;zeros(N+1,1)];
b=zeros((3*N),(2*N+1));
idx=tril(ones((3*N),(2*N+1)))-tril(ones((3*N),(2*N+1)),-N);
b(idx>0)=repmat(x2(:),(2*N+1),1);
m=1:(2*N-1);
corr(m)=sum(a.*b(:,m))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER