Question

i am using a code for surface approximation of triangulation ,which is copied here

[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

this is a part of a larger code, when i run the code it gives the following errors in 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;

According to my search i have got the right syntax of pinv, "Input must be 2D" error is beyond my understanding, if any one can tel me a way to solve this issue

Was it helpful?

Solution

According to the information given by you, it looks that c9 is a trivial 3-D matrix i.e. its second dimension is one. such dimensions are called as singleton dimensions. Squeeze is the command used to collapse such dimensions. You should simply do,

c9=squeeze(c9); %before doing pinv

This will make c9 a 2-D matrix and then its SVD can be calculated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top