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

Thread Subject:
Statistic analysis of specific matrix elements

Subject: Statistic analysis of specific matrix elements

From: Barry

Date: 22 Oct, 2010 08:28:04

Message: 1 of 7

Hello all,

I am a new Matlab user. I have a task to analyze diffraction spots (six spots) from scattering experiments. I want to do statistic analysis (e.g. total count, max, minimum and average counts, etc). My data is a matrix 250x250 with specific counting number per element. For each spot I made a circle as border to which elements (rows and column) to be included in counting. The border I wrote using if then construction:

for i=1:6
     if (xpix-XC(1,i)).^2+(ypix-YC(1,i)).^2<=R^2
     then label x(i,j) and do counting
    end
end

Could anyone help me... i tried as hard as i can but not successful yet.

Thank you
Barry

Subject: Statistic analysis of specific matrix elements

From: Miroslav Balda

Date: 22 Oct, 2010 09:13:03

Message: 2 of 7

"Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rhuk$es4$1@fred.mathworks.com>...
> Hello all,
>
> I am a new Matlab user. I have a task to analyze diffraction spots (six spots) from scattering experiments. I want to do statistic analysis (e.g. total count, max, minimum and average counts, etc). My data is a matrix 250x250 with specific counting number per element. For each spot I made a circle as border to which elements (rows and column) to be included in counting. The border I wrote using if then construction:
>
> for i=1:6
> if (xpix-XC(1,i)).^2+(ypix-YC(1,i)).^2<=R^2
> then label x(i,j) and do counting
> end
> end
>
> Could anyone help me... i tried as hard as i can but not successful yet.
>
> Thank you
> Barry

Hi Barry,
If you like to receive a propper answer, you have to describe your problem perfectly, otherwise there could not be any answer. So, what is the name of your matrix, what is xpix, ypix, What is XC, YC, what is j?
Mira

Subject: Statistic analysis of specific matrix elements

From: Barry

Date: 22 Oct, 2010 09:44:03

Message: 3 of 7

Thank you very much for your quick reply and i am sorry for not defining some variables. As i said i have a matrix 250x250, so i just assigned row (1...250) as ypix and column (1..250) as xpix, which stands for pixels. XC and YC are center of each circle (XC,YC). XC(1,i) and YC(1,i) are center for each circle (i=1:6, spot number): R is radius of circle. I want to do statistical calculation only for matrix elements inside each circle but i could not figure out how to take positions (x,y position) of all pixels included in each spot.

Hope this clarify my problem.

Barry

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rkiv$g3$1@fred.mathworks.com>...
> "Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rhuk$es4$1@fred.mathworks.com>...
> > Hello all,
> >
> > I am a new Matlab user. I have a task to analyze diffraction spots (six spots) from scattering experiments. I want to do statistic analysis (e.g. total count, max, minimum and average counts, etc). My data is a matrix 250x250 with specific counting number per element. For each spot I made a circle as border to which elements (rows and column) to be included in counting. The border I wrote using if then construction:
> >
> > for i=1:6
> > if (xpix-XC(1,i)).^2+(ypix-YC(1,i)).^2<=R^2
> > then label x(i,j) and do counting
> > end
> > end
> >
> > Could anyone help me... i tried as hard as i can but not successful yet.
> >
> > Thank you
> > Barry
>
> Hi Barry,
> If you like to receive a propper answer, you have to describe your problem perfectly, otherwise there could not be any answer. So, what is the name of your matrix, what is xpix, ypix, What is XC, YC, what is j?
> Mira

Subject: Statistic analysis of specific matrix elements

From: Miroslav Balda

Date: 22 Oct, 2010 10:23:03

Message: 4 of 7

"Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rmd3$n6o$1@fred.mathworks.com>...
> Thank you very much for your quick reply and i am sorry for not defining some variables. As i said i have a matrix 250x250, so i just assigned row (1...250) as ypix and column (1..250) as xpix, which stands for pixels. XC and YC are center of each circle (XC,YC). XC(1,i) and YC(1,i) are center for each circle (i=1:6, spot number): R is radius of circle. I want to do statistical calculation only for matrix elements inside each circle but i could not figure out how to take positions (x,y position) of all pixels included in each spot.
>
> Hope this clarify my problem.
>
> Barry
>
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rkiv$g3$1@fred.mathworks.com>...
> > "Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rhuk$es4$1@fred.mathworks.com>...
> > > Hello all,
> > >
> > > I am a new Matlab user. I have a task to analyze diffraction spots (six spots) from scattering experiments. I want to do statistic analysis (e.g. total count, max, minimum and average counts, etc). My data is a matrix 250x250 with specific counting number per element. For each spot I made a circle as border to which elements (rows and column) to be included in counting. The border I wrote using if then construction:
> > >
> > > for i=1:6
> > > if (xpix-XC(1,i)).^2+(ypix-YC(1,i)).^2<=R^2
> > > then label x(i,j) and do counting
> > > end
> > > end
> > >
> > > Could anyone help me... i tried as hard as i can but not successful yet.
> > >
> > > Thank you
> > > Barry
> >
> > Hi Barry,
> > If you like to receive a propper answer, you have to describe your problem perfectly, otherwise there could not be any answer. So, what is the name of your matrix, what is xpix, ypix, What is XC, YC, what is j?
> > Mira

Hi Barry,

I do not think that you clarified your problem. I explained it for me myself:
There is the "matrix", say A, of pixels. a "spot'" belogs to every pixel and has 6 elements, right? In this case A is not a matrix, but array of 3 dimensions. Next, why are you making circle over a "spot"? I mean that the circle be done in the matrix A in the point XC, YC (?) and afterwards you find the statistics over a spot, right? Finding indeces of pixels belonging to the circe is only a problem of trigonometry.
If you think that I am wrong, you have to describe it better. More ove what is j?

By the way, messages in this Newsgroup have to be written >>after<< the reply.

Mira

Subject: Statistic analysis of specific matrix elements

From: Barry

Date: 22 Oct, 2010 10:54:04

Message: 5 of 7

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rom7$fme$1@fred.mathworks.com>...
> "Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rmd3$n6o$1@fred.mathworks.com>...
> > Thank you very much for your quick reply and i am sorry for not defining some variables. As i said i have a matrix 250x250, so i just assigned row (1...250) as ypix and column (1..250) as xpix, which stands for pixels. XC and YC are center of each circle (XC,YC). XC(1,i) and YC(1,i) are center for each circle (i=1:6, spot number): R is radius of circle. I want to do statistical calculation only for matrix elements inside each circle but i could not figure out how to take positions (x,y position) of all pixels included in each spot.
> >
> > Hope this clarify my problem.
> >
> > Barry
> >
> > "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rkiv$g3$1@fred.mathworks.com>...
> > > "Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rhuk$es4$1@fred.mathworks.com>...
> > > > Hello all,
> > > >
> > > > I am a new Matlab user. I have a task to analyze diffraction spots (six spots) from scattering experiments. I want to do statistic analysis (e.g. total count, max, minimum and average counts, etc). My data is a matrix 250x250 with specific counting number per element. For each spot I made a circle as border to which elements (rows and column) to be included in counting. The border I wrote using if then construction:
> > > >
> > > > for i=1:6
> > > > if (xpix-XC(1,i)).^2+(ypix-YC(1,i)).^2<=R^2
> > > > then label x(i,j) and do counting
> > > > end
> > > > end
> > > >
> > > > Could anyone help me... i tried as hard as i can but not successful yet.
> > > >
> > > > Thank you
> > > > Barry
> > >
> > > Hi Barry,
> > > If you like to receive a propper answer, you have to describe your problem perfectly, otherwise there could not be any answer. So, what is the name of your matrix, what is xpix, ypix, What is XC, YC, what is j?
> > > Mira
>
> Hi Barry,
>
> I do not think that you clarified your problem. I explained it for me myself:
> There is the "matrix", say A, of pixels. a "spot'" belogs to every pixel and has 6 elements, right? In this case A is not a matrix, but array of 3 dimensions. Next, why are you making circle over a "spot"? I mean that the circle be done in the matrix A in the point XC, YC (?) and afterwards you find the statistics over a spot, right? Finding indeces of pixels belonging to the circe is only a problem of trigonometry.
> If you think that I am wrong, you have to describe it better. More ove what is j?
>
> By the way, messages in this Newsgroup have to be written >>after<< the reply.
>
> Mira

Hi Mira,

I have a diffraction data that for fcc crystals consist of six spots (hexagonal). The spots are formed because the intensity at specific places or elements inside matrix (xpixels times ypixels, or 250x250) are higher than the rest of matrix. So, I have a 2D matrix with dimension 250x250 , let say A, the value of each matrix element is different, so when you plot for example surf(X,Y,Count) where [X,Y]=meshgrid(xpixel,ypixel). Count is value of A(xpixel,ypixel).

I made six circles because of six spots and want to know which elements in this case positions of (xpixel,ypixel) inside each circle and then do statistical analysis for each circle. so index i=1:6 is a label for each spot. I wrote XC and YC as vector 1x6 to label center of six circles while R is radius of circles containing spots. x(j,k) just to label x and y positions that included in each spot.

Regards,

Barry

Subject: Statistic analysis of specific matrix elements

From: Miroslav Balda

Date: 22 Oct, 2010 15:24:03

Message: 6 of 7

"Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rqgc$8t9$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rom7$fme$1@fred.mathworks.com>...

SNIP

> Hi Mira,
>
> I have a diffraction data that for fcc crystals consist of six spots (hexagonal). The spots are formed because the intensity at specific places or elements inside matrix (xpixels times ypixels, or 250x250) are higher than the rest of matrix. So, I have a 2D matrix with dimension 250x250 , let say A, the value of each matrix element is different, so when you plot for example surf(X,Y,Count) where [X,Y]=meshgrid(xpixel,ypixel). Count is value of A(xpixel,ypixel).
>
> I made six circles because of six spots and want to know which elements in this case positions of (xpixel,ypixel) inside each circle and then do statistical analysis for each circle. so index i=1:6 is a label for each spot. I wrote XC and YC as vector 1x6 to label center of six circles while R is radius of circles containing spots. x(j,k) just to label x and y positions that included in each spot.
>
> Regards,
>
> Barry

Hi Barry,

Now it is all clear (I hope). The matrix A contains intensities (positive numbers).
There are areas of higher intensities called "spots' with centers in points (XC,YC). You wish to make some statistical analysis of those spots inside circular domains of the radius R. If only this had been said just at the beginning ...
Since coordinates of the points are integers, all variables R, XC, YC, should also be integers.
The code that, I hope, solves your problem is rather simple. It has 2 modules: the initial script (main program), and the function for calculating statistics. I have prepared both modules, which you may change under your requirements:
Now, there could be any number of spots in the matrix A.

Main program:

% Barry.m Statistical analysi of a special matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Setup A, R, XC, YC

[x,y] = meshgrid(-R:R);
XY = x.^2+y.^2 <= R^2; % Logical indeces of points inside any circle
for i = 1:length(XC) % a cycle over spots
    [peak,ave,rms] = makestats(A(XC(i)-R:XC(i)+R, YC(i)-R:YC(i)+R), XY);
end

M-function for evaluation of statistics:

function [peak,ave,rms] = makestats(Ai,XY)
% MAKESTATS function for calculating statistics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ai i-th square matrix of intensities round a point (XC,YC)
% XY logical matrix of points inside a circle

Peak = sum(A(XY));
ave = mean(A(XY));
rms = std(A(XY));

I could not test it having no data. However, you may do it yourselves.
I hope that there are not many errors.

Best regards

Mira

Subject: Statistic analysis of specific matrix elements

From: Miroslav Balda

Date: 22 Oct, 2010 15:42:04

Message: 7 of 7

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9saaj$a7g$1@fred.mathworks.com>...
> "Barry " <brrstvnssn4@googlemail.com> wrote in message <i9rqgc$8t9$1@fred.mathworks.com>...
> > "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rom7$fme$1@fred.mathworks.com>...
>
> SNIP

> Peak = sum(A(XY));
> ave = mean(A(XY));
> rms = std(A(XY));

Of course that the last 3 lines of the code shoud be read as it follows:

Peak = sum(Ai(XY));
ave = mean(Ai(XY));
rms = std(Ai(XY));

Mira

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us