Peak labeling on spectroscopic data using plotjdx function
显示 更早的评论
I am plotting some Raman spectroscopy data, using the plotjdx function created by Micke Malmstrom (here; requires the Bioinformatics Toolbox). This works great, but I would like to find and label the peaks, and cannot figure out where in the script I should do this. My sense is that I need to use the findpeaks function built into MATLAB, but I have yet to incorporate it successfully. Do you have advice on where I could insert the "findpeaks" function and related lines of code?
Here is the plotjdx function. I have attached a test spectra file.
function h=plotjdx(variable,h)
% h=plotjdx(variable,h) Plots a (selection of) jdx file(s) in a new or
% specified figure. If no file is specified then the function ask for user
% to select files...
%
% input 'variable' can be:
% - a 'filename' of a jdx file,
% - a cell with filenames to several jdx files or
% - JCAMPStruct to be plotted in
%
% input figure handle 'h' is optional
%
% BSD micke.malmstrom@gmail.com
% Version 2014-12-18
if nargin==0
% If no input, ask for files
[filename,folderpath] = uigetfile({'*.*'},...
'Select the .jdx files to plot','MultiSelect','on');
% see if handle to fig is specified
if exist('h','var')
h=figure(h);clf, hold on
else % make new figure
h=figure;clf, hold on
end
if iscell(filename)
%its several files
files=filename;
% now plot all files in same figure h
for ii=1:length(filename)
h=plotjdx([folderpath files{ii}],h);
end
legend show
return
else %is only one file so plot it
h=plotjdx([folderpath filename],h);
return
end
% if the input is characters then 'variable' is a filename
elseif ischar(variable)
%import and plot the file
variable=jcampread(variable);
h=plotjdx(variable);
% if the input is a cell then 'variable' is a bunch of filenames
elseif iscell(variable)
% see if handle to fig is specified
if exist('h','var')
h=figure(h);clf, hold on
else % make new figure
h=figure;clf, hold on
end
% now plot all files in same figure h
for ii=1:length(variable)
h=plotjdx([variable{ii}],h);
end
legend show
return
% if the input is a structure then 'variable' is the actual JCAMPStruct
elseif isstruct(variable)
data = variable.Blocks(1);
h=plot(data.XData,data.YData, 'DisplayName',variable.Title);
xlabel(data.XUnits);
ylabel(data.YUnits);
end
2 个评论
Mathieu NOE
2020-11-25
hello
sure you need findpeaks
there is an example in the documentation for how to plot the peaks
that must be inserted after the plot command , for example in the last section of your code :
% if the input is a structure then 'variable' is the actual JCAMPStruct
elseif isstruct(variable)
data = variable.Blocks(1);
h=plot(data.XData,data.YData, 'DisplayName',variable.Title);
xlabel(data.XUnits);
ylabel(data.YUnits);
end
now, beside that I am a bit surprised to see that this function (plotjdx) call itself in the script
very surprising !!!
Natalie Raia
2020-11-30
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!