Why won't fitpeaks work on my data?

조회 수: 4 (최근 30일)
Sam
Sam 2021년 12월 8일
답변: Image Analyst 2021년 12월 13일
Hi, I have a Raman spectrum in a .txt file, with one column of my x axis values and another with my y axis. I am trying to write a script so I can conduct bulk analysis of lots of spectra, but I am struggling!
I am using the following code to read in my data.
data = importdata('RamanData.txt');
plot(data);
[pks,loc] = findpeaks(data);
findpeaks(data)
MATLAB plots my data (alongside a diagonal line?)
I also get these errors:
Error using findpeaks
Expected Y to be a vector.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in FindPeak (line 3)
[pks,loc] = findpeaks(data);
Is this an error in my data set up, script or should I be using a different function?

채택된 답변

Rik
Rik 2021년 12월 8일
I guess boldly:
Your txt file contains both the magnitude and the wavelength. The plot function gave you a plot with two lines: one with the magnitude and one with the wavelenghts. That is why your x-axis is 0-1700, instead of 470(?) to 2000 nm(?).
You need to separate the matrix that importdata returned into the two respective vectors. Then you can supply the wavelength only to findpeaks.
You can confirm this by looking at the size of data.
  댓글 수: 1
Sam
Sam 2021년 12월 13일
Thank you very much, I was not aware that only the wavelength was required!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 12월 13일
It's the magnitude that is required if you want to get indexes.
data = importdata('RamanData.txt');
wavelengths = data(:, 1); % Wavelengths in column 1
magnitude = data(:, 2); % Signal magnitude in column 2
plot(wavelengths, magnitude, 'b-', 'LineWidth', 2);
[peakValues, indexesOfPeaks] = findpeaks(magnitude);
wavelengthsOfPeaks = wavelengths(indexesOfPeaks);
Or specify wavelength as the second input if you want wavelength for location instead of indexes.
data = importdata('RamanData.txt');
wavelengths = data(:, 1); % Wavelengths in column 1
magnitude = data(:, 2); % Signal magnitude in column 2
plot(wavelengths, magnitude, 'b-', 'LineWidth', 2);
[peakValues, wavelengthsOfPeaks] = findpeaks(magnitude, wavelengths);

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by