如何使用以下方法解决问题。我试图通过使用它的x和y组件(嵌入在c和r中)创建向量distvec和magvec,同时附加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
???订阅的分配维度不匹配。
由于
答案 0 :(得分:1)
下标的赋值维度不匹配通常意味着左侧数组的大小与右侧的数组不匹配。
由于您正在进行如此多的数组分配,而且我们无法看到数组的大小,因此诊断起来非常困难。
错误还说了什么?它是否指定哪一行是问题?
我关注这两行:
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阵列。