Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

tell me how to calculate histc(x,y)

Asked by BANI tita on 7 Jun 2013

can you tell me how to calculate histc two variable (x and y) in matlab ;thank you

0 Comments

BANI tita

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek on 7 Jun 2013

4 Comments

Azzi Abdelmalek on 7 Jun 2013

Give a short example

BANI tita on 7 Jun 2013
   x=[1 3 3 ;3 2 3; 1 2 1;3 2, 4; 5 5 1]
y=[1; 2; 3;4;5]

for k=1:3

    Mux(k,:)=mean(x(y==k,3));
    Muy(k,:)=mean(y==k,1);
    Sigmax(k,:) = std(x(y==k,3));
    Sigmay(k,:) = std(y==k,1);
end
% return
a=2;
[tmpx, idx]=sort(Mux);
[tmpy, idy]=sort(Muy);
MumoinsSigmax = Mux(idx,:)-a*Sigmax(idx,:),;
MuplusSigmax = Mux(idx,:)+a*Sigmax(idx,:),;
MumoinsSigmay = Mux(idy,:)-a*Sigmax(idy,:),;
MuplusSigmay = Mux(idy,:)+a*Sigmax(idy,:),;

minIntervalx = [-Inf,MumoinsSigmax:MuplusSigmax],;

minIntervaly = [-Inf,MumoinsSigmay:MuplusSigmay],;

minIntervalx = [minIntervalx,Inf],;

minIntervaly = [minIntervaly,Inf],;

Lx = length(minIntervalx),; Ly = length(minIntervaly),;

Freq = zeros(Lx,Ly);

 edges= {minIntervalx,minIntervaly}

Freq = histc(y(:),x(:),edges);

BANI tita on 7 Jun 2013

replace x and y with:

x=[1 3 3 ;3 2 3; 1 2 1;3 2, 3; 3 2 1]

y=[1; 1; 3;3;2]

Azzi Abdelmalek

Contact us