Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this prime symbol do - MATLAB?

Tags:

matlab

I am working with some matlab code I inhereted from another person, I dont understand the meaning of the line q =[q; qi']. I feel like i should be able to just remove it, so that q = distribuc...

function [ q ] = ObtainHistogramForEachTarget( state, numberOfTargets, image, q )

    for i=1 : numberOfTargets
        qi = distribucion_color_bin_RGB2(state(i).xPosition,state(i).yPosition,state(i).size,image,2);
        q = [q; qi'];
    end
end

Can anyone explain this to me?

like image 283
Eamonn McEvoy Avatar asked Feb 05 '13 21:02

Eamonn McEvoy


3 Answers

MATLAB has several built-in functions to manipulate matrices. The special character, ', for prime denotes the transpose of a matrix.

The statement A = [ 1 2 3;4 5 6;7 8 9]' produces the matrix

A = 
   1 4 7 
   2 5 8
   3 6 9

hope this helps

like image 51
legrandviking Avatar answered Oct 01 '22 22:10

legrandviking


From Matlab's help

help ctranspose
' Complex conjugate transpose.
X' is the complex conjugate transpose of X.

 B = ctranspose(A) is called for the syntax A' (complex conjugate
 transpose) when A is an object.
like image 20
Mikrasya Avatar answered Oct 01 '22 23:10

Mikrasya


The [X ; Y] syntax concatenates two matrices vertically. So that line is adding the just-computed results to the already computed q. If you simply reassigned q, you would be discarding all the computations the function had already done each time through the loop.

The forward apostrophe ' does a complex conjugate and transposes a matrix. I would guess that distribucion_color_bin_RGB2 probably returns a real-valued column vector, and the author wanted to flip it to horizontal before appending it to the results matrix.

As @ja72 pointed out, it's better style to use .' (just transpose) by default and ' only when you actually mean a complex conjugate, even if you expect your data to be real.

like image 21
aschepler Avatar answered Oct 01 '22 22:10

aschepler