1
votes

how do I resolve the problem with the following. I am trying to create vectors distvec and magvec by using it's x and y components (embedded in c and r) while appending the z dimiensions.

for pxRow = 1:h % fixed pixel row
 for pxCol = 1:w % fixed pixel column

 for r = 1:h % row of distant pixel
 for c = 1:w % column of distant pixel

 R(c,r) = sqrt((r-pxRow)^2 + (c-pxCol)^2);                               % pythagoras theorem to get distance to each pixel
 O(c,r) = sqrt(Ox(c,r).^2 + Oy(c,r).^2);                                 % orientation vector 
 If(c,r) = sqrt((dx(c,r)).^2 + (dy(c,r)).^2);                            % magnitude of current 
 Rxs(c,r) = R(c,r)./norm(R(c,r));                                        % unit vector from x to s                     
 dist(c,r) = Rxs(c,r)./R(c,r);
 mag(c,r) = O(c,r).*If(c,r);
 distvec(c,r) = [dist(c) dist(r) 0];
 magvec(c,r) = [mag(c) mag(r) 0];                      
 b(c,r) = cross(magvec,distvec);% b field = If(s)O(s) x Rxs/R.^2  BIOT SAVART LAW
 end
 end
 B(i) = {b}; % filling a cell array with results. read below

??? Subscripted assignment dimension mismatch.

Thanks

1

1 Answers

1
votes

A subscripted assignment dimension mismatch usually means that the size of the array on the left and the array on the right do not match.

Since you're doing so many array assignments, and we can't see how big the arrays are, it's very difficult to diagnose.

What else does the error say? Does it specify which line is the problem?

I'm concerned about these two lines:

distvec(c,r) = [dist(c) dist(r) 0];
magvec(c,r) = [mag(c) mag(r) 0];  

And this line

B(i) = {b};

Check that the sizes of the left and right vectors are the same using the size function or similar.

Before the for loops, add

size(distvec)
size(magvec)
size(B)
size(b)

distvec and magvec should both be 3D arrays.