Paulo Araujo
Paulo Araujo

Reputation: 61

How to interpret these command lines written in MATLAB?

A is a matrix containing some matching points for a stereo vision system and the cameras' matrices. Regarding the problem, I know that I need to minimize a cost function relating the distance between a projected and a detected point.

Investigating some functions inside MATLAB I found this code that I suppose does this minimization because of the output I receive.

I'd like to understand, if possible, what mathgician is happening here:

    [~,~,V] = svd(A);
    X = V(:,end);
    X = X/X(end);

Thanks in advance for any help

Upvotes: 0

Views: 58

Answers (1)

nekomatic
nekomatic

Reputation: 6284

[~,~,V] = svd(A);

performs a singular value decomposition of the matrix A which produces three matrices as output. The first two of these are ignored (by assigning them to ~, according to MATLAB convention) and the third is assigned to the variable V.

X = V(:,end);

assigns the rightmost column of matrix V to the variable X - the : means 'all', in this case 'all the rows'

X = X/X(end);

divides each element of X by the last element of X - or in other words, scales the vector X so that its last element is equal to 1.

Upvotes: 1

Related Questions