필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Mohamad Khairul Ikhwan Zulkarnain
댓글: Guillaume 2018년 9월 14일
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
Mohamad Khairul Ikhwan Zulkarnain
I got more than one peak at the same time bcs when i select the number of row for wavelength, i select more than one row which eventually will create more than one peak at a time. I dont think my peak share the same x-vector since each peak has its own row but as you see in the first picture, there are some part of the peak is overlapping. Cant we just sum it up? If not, what should I do to sum it up? Can you show it to me?

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

채택된 답변

jonas
jonas 2018년 9월 14일
편집: jonas 2018년 9월 14일
They key is to resample the curves along a common x-vector. You can do this by interp1. Just add these new lines of code:
% ... old code
Peak = (int_fact.*(1./(1+(num/denom).^2)));
% ...New code begins here
x=new_wavelength(selectedrow,:);
y=Peak;
% Remove rows with NaNs
x(isnan(y(:,1)),:)=[];
y(isnan(y(:,1)),:)=[];
% Number of peaks
np=size(y,1);
% New xvec
xh=min(x(:)):1e-3:max(x(:)); %new x vector
% Preallocate new peak vector
yh=nan(size(x,1),size(xh,2));
%Interpolate one peak at a time
for i=1:np
yh(i,:)=interp1(x(i,:),y(i,:),xh);
end
% Sum column-wise, exclude nans
ysum=nansum(yh,1);
% Plot
plot(xh,ysum)
First three wavelengths of Ferum:
  댓글 수: 5
jonas
jonas 2018년 9월 14일
편집: jonas 2018년 9월 14일
No problem! Should work now.
Mohamad Khairul Ikhwan Zulkarnain
Thank you! You're lifesaver!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by