2012-07-03 8 views
0

교차 제품 기능에 문제가 있습니다. 각 픽셀에 대해 두 벡터의 외적을 취한 다음 모든 픽셀의 결과를 합산해야합니다.matlab - 제품 간 오류

i=1;  
[h,w,d] = size(current_vec); 
for pxRow = 1:h % fixed pixel row 
for pxCol = 1:w % fixed pixel column 
for pxsize = 1:d 

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

bfield(c,r,dpth) = cross(current_vec(c,r,dpth),dist_vec(c,r,dpth));        % pythagoras theorem to get distance to each pixel                  % unit vector from x to s      

end 
end 
end 
Bfield(i) = {bfield}; % filling a cell array with results. read below 
i = i+1; 
end 
end 
end 


??? Error using ==> cross at 37 
A and B must have at least one dimension of length 3. 

??? Error using ==> cross at 37 
A and B must have at least one dimension of length 3. 

Error in ==> MAC2 at 71 
bfield(c,r,dpth) = cross(current_vec(c,r,dpth),dist_vec(c,r,dpth));        

위반이 current_vec 벡터와 dist_vec은 다음과 같다 그러나 :

>> size(current_vec) 

ans = 

    35 35  3 

>> size(dist_vec) 

ans = 

    35 35  3 

그래서 내가 아는 한 그들은 십자가 제품에 사용되는 기준을 입력합니다. 왜 이런 경우가 아닌가요?

+0

'cross'의 호출에서 벡터가 아닌 스칼라 만있는'current_vec (c, r, dpth)'와'dist_vec (c, r, dpth)'를 사용합니다. –

답변

3

당신은 cross의 벡터화 된 형태로 사용할 필요가 :

bfield = cross(current_vec,dist_vec); 

cross 3. 중첩 된 루프로하고 있었던 방법의 길이 첫 번째 차원에서 작동을, 당신은 하나의 요소를 액세스하는 (스칼라). 스칼라로 스칼라를 교차시킬 수는 없습니다.