How do I combined all peak to become one spectral line?
Show older comments

Hi guys, from the code I have I managed to produce the graph:
%get list of element, prompt user to select one, and get content of element file
filelist = dir('*.txt');
[~, elementlist] = arrayfun(@(f) fileparts(f.name), filelist, 'UniformOutput', false);
[elementindex, ok] = listdlg('ListString', elementlist, 'PromptString', 'Select an element', 'SelectionMode', 'single');
if ~ok, return; end %terminate if user click cancel
elementdata = importdata(filelist(elementindex).name);
assert(isnumeric(elementdata), 'Element does not have data'); %abort if the file does not contain a matrix
%build wavelength array
step = 0.02;
ss = 100;
steparray = -step*ss : step : step*ss;
new_wavelength = (elementdata(:, 1) + steparray); %no loop needed. Requires R2016b or latter
%get row selection
[selectedrow, ok] = listdlg('ListString', compose('%f', elementdata(:, 1)), 'PromptString', 'Select a wavelength', 'SelectionMode', 'multiple');
if ~ok, return; end %terminate if user click cancel
%build Peak vector for selected row
Delta_lambda = 0.2;
int_fact = elementdata(selectedrow, 2);
num = new_wavelength(selectedrow,ss+1)-new_wavelength(selectedrow,:);
denom = Delta_lambda/2;
Peak = (int_fact.*(1./(1+(num/denom).^2)));
%combined peak vector for selected row
plot(new_wavelength(selectedrow, :).', Peak.')
How do I combined all the peak that I chose to become as the graph below bcs I have try by using sum(peaks) but i doesnt work so im not sure how should I do it. One of the expert(Mathworks society) told me to resample each row to the same wavelength before i can sum it but im not sure how should i do it.

I have attached the element file as well. Thanks in advanced.
3 Comments
How did you even plot the three peaks at the same time? When I run the code I get one peak and, if I understand correcrtly, if I run the script again it overwrites the old peak. Did you just use 'hold on'?
Also, do the peaks share the same x-vector? That's important, because you will not be able to simply sum them up if they are not sampled at the same xvalues.
Mohamad Khairul Ikhwan Zulkarnain
on 14 Sep 2018
Guillaume
on 14 Sep 2018
For info, (a bit late), this is a continuation of why-am-i-getting-an-error-of-subscripted-assignment-dimension-mismatch
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
