How to get the projection of a 2D colorplot on x axis?

조회 수: 11 (최근 30일)
aneps
aneps 2014년 6월 1일
답변: Image Analyst 2014년 6월 2일
I have a 2D color plot as following:
how can I choose a region, for example 15 to 25 (axes not labelled in the figure.. the Y axis range from 0 to 40 in this figure) and project on X axis so that I get a 1D histogram? To make clear, the program should sum up the values along Y axis (from yrange 15 to 25) for each X values and then plot SumY against X. This will make a 1D projection of the colormap.
In order to plot the colormap (the above image), I am using the following code:
A=load('Data.dat');
Dat=[Data(:,1) Data(:,2)];
nbins=[100 100];
n=hist3(Dat,nbins);
n1 = n;
n1(size(n,1) + 1, size(n,2) + 1) = 0;
xb = linspace(min(Dat(:,1)),max(Dat(:,1)),size(n,1)+1);
yb = linspace(min(Dat(:,2)),max(Dat(:,2)),size(n,1)+1);
figure
pcolor(xb,yb,n1);
I tried the following:
A1=[A(:,1) A(:,2)];
index= find(A1(:,2)>=15&A1(:,2)<=25);
New=A1(index,:);
vp=sum(New,2);
hist(vp,100)
But along the X axis in the histogram (hist(vp, 100)) it is showing the values from 15 to 65! but in real data (New in the code) it is from 0 to 40 only! something mistake in this code I think!
Thank you

채택된 답변

Image Analyst
Image Analyst 2014년 6월 2일
verticalProjection = sum(theArray, 2); % Sum horizontally along columns in each row.
horizontalProjection = sum(theArray, 1); % Sum vertically along rows in each column.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by