Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Assignment has more non-singleton rhs dimensions than non-singleton subscripts

542 views
Skip to first unread message

Kevin

unread,
Jul 14, 2009, 10:16:03 AM7/14/09
to
Hello I'm trying to make two matrices and use fourier transforms to effectively take a 3D convolution of the functions that the matrices represent. My code is as follow:

function W= Nconvolve(t_end, beamdistance, i1,i2,j)
k=(0:.001:t_end);

for h=(1:length(k))
g= (TwoDG(k(h), beamdistance, i1, i2,j));
D(:,:,h)=g;


end

x1= (-.004:.001:.004);
x2= (-.004:.001:.004);

for f= (1:length(x1))
for e= (1:length(x2))
for h=(1:length(k))


sigma_x= 1;
sigma_z= 1;
F(f,e) = exp((-((x1(f))^2)/(2*((sigma_x)^2)))-(((x2(e))^2)/(2*((sigma_z)^2))));

Q(:,:,h)=F;
end;
end;

end;

X= fft([D zeros(1,length(Q)-1)]);

Y= fft([Q zeros(1,length(New)-1)]);

W= ifft(X.*Y);

but when i run this, it tells me that

"Assignment has more non-singleton rhs dimensions than non-singleton
subscripts

Error in ==> Nconvolve at 23
Q(:,:,h)=F;"

and I cannot figure out why. Any advice? Thanks in advance.

Alan B

unread,
Jul 14, 2009, 10:37:01 AM7/14/09
to
"Kevin " <ke...@virginia.edu> wrote in message <h3i3v3$rn6$1...@fred.mathworks.com>...

This doesn't exactly answer your question, but do you know about convn, or fftn? Also, your triple loop doesn't really make sense. For one, you can eliminate the 'e' and 'f' loops by using meshgrid and computing F for vector arguments instead of scalar. sigma_x and sigma_z are constant so they should be defined outside the loop. Q doesn't seem to depend on h, so why are you looping over h? You might use repmat instead.

Kevin

unread,
Jul 14, 2009, 12:57:05 PM7/14/09
to
Well I am trying to make Q a 3D matrix that has the value of F through each step of time (represented by h), so by looping through h I was attempting to fill the 3D matrix with the solution to F at each time point. I just don't understand why that causes an error.

Bruno Luong

unread,
Jul 14, 2009, 2:00:18 PM7/14/09
to
"Kevin " <ke...@virginia.edu> wrote in message <h3idd1$opj$1...@fred.mathworks.com>...

> Well I am trying to make Q a 3D matrix that has the value of F through each step of time (represented by h), so by looping through h I was attempting to fill the 3D matrix with the solution to F at each time point. I just don't understand why that causes an error.

I see error; but I think it's better you see by yourself. Use DBSTOP IF ERROR, run your code and check the dimensions for Q and F.

Bruno

Matt

unread,
Jul 14, 2009, 3:49:02 PM7/14/09
to
"Kevin " <ke...@virginia.edu> wrote in message <h3i3v3$rn6$1...@fred.mathworks.com>...

As an example, suppose size(F) = [m,n,p,q,r] and you have an assignment like

Q(1:m,1:n)=F;

This is only a valid assignment if p=q=r=1. Otherwise, you get the error message indicated.

0 new messages