matlab???下标赋值维度不匹配

matlab???下标赋值维度不匹配,matlab,Matlab,如何解决以下问题。我试图通过使用向量的x和y分量(嵌入c和r中)来创建向量distvec和magvec,同时添加z元素 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)

如何解决以下问题。我试图通过使用向量的x和y分量(嵌入c和r中)来创建向量distvec和magvec,同时添加z元素

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
???下标赋值维度不匹配


感谢

下标赋值维度不匹配通常意味着左侧数组和右侧数组的大小不匹配

由于您要执行如此多的阵列分配,而且我们无法看到阵列有多大,因此很难进行诊断

错误还说明了什么?它是否指定问题出在哪一行

我关心这两条线:

distvec(c,r) = [dist(c) dist(r) 0];
magvec(c,r) = [mag(c) mag(r) 0];  
这条线呢

B(i) = {b};
使用大小函数或类似函数检查左右向量的大小是否相同

在for循环之前,添加

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

distvec和magvec都应该是3D数组。

下标赋值维度不匹配通常意味着左侧数组和右侧数组的大小不匹配

由于您要执行如此多的阵列分配,而且我们无法看到阵列有多大,因此很难进行诊断

错误还说明了什么?它是否指定问题出在哪一行

我关心这两条线:

distvec(c,r) = [dist(c) dist(r) 0];
magvec(c,r) = [mag(c) mag(r) 0];  
这条线呢

B(i) = {b};
使用大小函数或类似函数检查左右向量的大小是否相同

在for循环之前,添加

size(distvec)
size(magvec)
size(B)
size(b)
distvec和magvec都应该是3D阵列