Center of Gravity of given file

8 次查看(过去 30 天)
Ques. I have to plot the center of gravity for the attached image using the hold on command. I can plot the 'xline' what I don't understand is how to get the co-ordinates of COG and plot them on the same figure where I have my spectrum. Or how to find the y-intercept?
%% Centre of Gravity
x1 = readData{1,1}(:,1);
y1 = readData{1,2}(:,1);
numerator = sum(x1 .* y1);
denominator = sum(y1);
COG = numerator / denominator
figure(2);
hold on; grid on;
plot(x,y,'Color','b','LineWidth',1.5);
xlabel('Wavelength(nm)');
ylabel('Intensity');
title('Initial Spectrum');
ylim([0 0.3]);
xline(COG, 'Color', 'r');
%plot(COG(index), y(index), 'or', 'LineWidth', 2);
%plot(COG, 'or', 'LineWidth', 2, 'MarkerSize', 6);
  2 个评论
Image Analyst
Image Analyst 2021-8-11
Data is a 3679 by 2 matrix. How is that an image? Please give code to turn '5.csv' into readData cell array.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2021-8-11
Wrong equation for centre of gravity. When you have uniform density, then the x coordinate of the COG is mean(x) and the y coordinate of the COG is mean(y)
Your COG equation is suitable for the case where you have a line with weights at x1 each of which weighs according to y1, and you are trying to find the COG of the line. However, in that case, there would be no vertical displacement.
  4 个评论
MUHAMMAD ANUS
MUHAMMAD ANUS 2021-8-11
What I have to do after this is compare different spectrums and their COG and analyse / look into the plots to make sense of the data
Walter Roberson
Walter Roberson 2021-8-11
Your xline() already marks the COG.
I have no idea what features are important for the purposes of comparing your spectra.
I know that when we were doing Magnetic Resonance Spectrum analysis to see if we could detect various forms of cancer, that the factors that turned out to be statistically important were not at all "flashy"; one of the key indicators turned out to be the ratio of two peaks, one of which just looked like a minor shoulder on water, and the other of which was a common chemical that had a lot of natural variation. Slightly higher levels of 1 combined with lower levels of the other was the key measure. Before us, no-one had ever realized the medical importance of that combination of circumstances.
Because of my experience, I can't make any blanket recommendations such as "mean squared error" or "most prominent peak".
In astronomy, a similarity might be that the key to understanding the classification of a particular star might not be the intensity of a peak by itself, but rather the ratio of several peaks. And that requires domain-specific knowledge of how to process the spectra.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by