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?
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With