简体   繁体   English

PINV命令中的MATLAB错误

[英]MATLAB ERROR IN PINV COMMAND

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 这是更大代码的一部分,当我运行代码时,它在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 根据我的搜索,我有正确的pinv语法,“输入必须是2D”错误超出我的理解,如果任何人可以给我一个方法来解决这个问题

According to the information given by you, it looks that c9 is a trivial 3-D matrix ie its second dimension is one. 根据您提供的信息,它看起来c9是一个普通的3-D矩阵,即它的第二维是1。 such dimensions are called as singleton dimensions. 这些尺寸称为单体尺寸。 Squeeze is the command used to collapse such dimensions. Squeeze是用于折叠此类尺寸的命令。 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. 这将使c9成为2-D矩阵,然后可以计算其SVD。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM