2013-12-11 91 views
0

我使用了三角測量的曲面近似,其在這裏複製的碼MATLAB ERROR IN PINV COMMAND

[totalTris,three] = size(tri); 
[totalPoints,two] = size(registeredPts); 

% 1. Find the 3 equations for each vertex, and 
%  place them in c_equations matrix; 
% c_equations = [A for vertex 1; 
%    A for vertex 2; ... 
%    A for vertex totalPoints] 
% c(point,row,:) gives one row from an A matrix 
Btotal = zeros(3,totalPoints); 
c_equations = zeros(3*totalPoints,3,9); 
for pointNum = 1:totalPoints 
    % B = [pixVal; x gradient; y gradient] at this vertex 
    z = pixelVals(pointNum); 
    B = [z; vGradientVecs(pointNum,1); vGradientVecs(pointNum,2)]; 

    % Compile all B matrices into a vector 
    Btotal(:,pointNum) = B; 

    % B = Ac 
    x = registeredPts(pointNum,1); 
    y = registeredPts(pointNum,2); 
    A = [1 x y x^2 y^2 x^3  (x^2)*y x*(y^2) y^3; ... 
     0 1 0 2*x 0 3*(x^2) 2*x*y y^2  0; ... 
     0 0 1 0 2*y 0  x^2  2*x*y 3*(y^2)]; 

    % Compile all A matrices into a vector 
    c_equations(pointNum,1,:) = A(1,:); 
    c_equations(pointNum,2,:) = A(2,:); 
    c_equations(pointNum,3,:) = A(3,:); 
end 

% 2. Find the c values for each triangle patch 
c = zeros(totalTris,9); 
c9 = zeros(9,9); 
for triNum = 1:totalTris 
    p1 = tri(triNum,1); 
    p2 = tri(triNum,2); 
    p3 = tri(triNum,3); 

    B9 = [Btotal(:,p1); Btotal(:,p2); Btotal(:,p3)]; 
    c9 = [c_equations(p1,1,:); c_equations(p1,2,:); c_equations(p1,3,:); ... 
      c_equations(p2,1,:); c_equations(p2,2,:); c_equations(p2,3,:); ... 
      c_equations(p3,1,:); c_equations(p3,2,:); c_equations(p3,3,:)]; 
    c(triNum,:) = pinv(c9)*B9; %linsolve(c9,B9); 
end 

end 

這是一個更大的碼的一部分,當我運行的代碼它給出了下面的錯誤MATLAB

Error using svd 
Input must be 2-D. 

Error in pinv (line 29) 
    [U,S,V] = svd(A,0); 
Error in findBPolyCoefficients (line 50) 
    c(triNum,:) = pinv(c9)*B9; 

根據我的搜索我有PINV的正確的語法,「輸入必須是2D」的錯誤超出了我的理解,如果任何一個可以電話我的方式來解決這個問題

+0

'c9'的大小是多少?在MATLAB中執行'size(c9)'並將其粘貼到此處。 –

+0

我做了大小(c9)並得到了9 1 9。我必須通過這個c9,我從中瞭解到的是這9個矩陣的9行和1列不知道我是否正確 – Jav

回答

2

阿科根據你給出的信息,看起來c9是一個平凡的3-D矩陣,即它的第二維是1。這樣的尺寸稱爲單體尺寸。 Squeeze是用於摺疊此類尺寸的命令。你應該簡單地做,

c9=squeeze(c9); %before doing pinv 

這將使c9 2 d矩陣,然後可以計算出它的SVD。

+0

感謝你讓我的一天: )在這樣做之後得到代碼運行 – Jav

+1

@Jav只需確認'squeezing'得到的'c9'就能給你想要的最終結果。它可能已經解決了錯誤,但你仍然需要檢查這是否是正確的做法。 –

+0

我無法得到正確的結果爲ma代碼,最後的形象是給問題,我認爲這是因爲它,但是當我會找到實際的原因,我會更新 – Jav