2012-06-06 71 views
1

如何解決以下問題。我試圖通過使用它的x和y組件(嵌入在c和r中)創建矢量distvec和magvec,同時附加z個dimiensions。matlab ???下標分配維度不匹配

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 

???下標分配尺寸不匹配。

由於

回答

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都應該是三維陣列。

相關問題