How to find centroid of experimental data ?

I am using MATLAB to calculate the centroid of data which i am importing from Excel spreadsheet. However, I have to use integration to calculate centroid. I am using trapz function to calculate integration.The formula which i am using here to integrate is mentioned in image.To implement (x*dx), i am using (1/2)*(d(x^2)).
But results are not up to mark.I am mentioning the code which i am using.
format longG;
filename='xyz.csv';
sheet=1;
col1=1; %Starting Column; Nx(charge) density Values %
col2=(col1)+1; %X values %
row1=10; %Starting Row Number%
row2=20; %Ending Row Number%
Data=csvread(filename); % Data File Reading%
% Access of Columns for Charge Density & X %
charge_density=(Data(row1:row2,col1))'; %Charge density Data in row matrix%
x=(Data(row1:row2,col2))';
max_charge_density=max(charge_density(:)); %maximum value of charge density%
normalized_charge_density=(charge_density./max_charge_density);
%%%%%%%%%%%%%%%%%%%%%For Double Gate FET %%%%%%%%%%%%%%%%%%%
Tfin=2; %Thickness of fin %
normalized_x=x/Tfin; %Normalized Distance%
x_square=normalized_x.^2; %square of normalized distance x%
%%%Integration of charge density with respect to Distance%%%
numerator=(trapz(x_square,normalized_charge_density))*(1/2);
denominator=trapz(normalized_x,normalized_charge_density);
%Centriod Calculation%
centroid= (numerator/denominator);

2 Kommentare

Image Analyst
Image Analyst am 17 Feb. 2018
Unfortunately you forgot to attach 'xyz.xlsx' so no one can run your code. The first problem I see is that you're trying to put all that code inside a cell by enclosing it in braces {}. The second problem I say was that you have a period after the "end" statement at the bottom. Fix those three things and then people might try your code and try to help you. http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
Amratansh Gupta
Amratansh Gupta am 17 Feb. 2018
Changes DONE. Now you can try.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Gefragt:

am 17 Feb. 2018

Kommentiert:

am 17 Feb. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by