Save marked point on plot
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello,
I would like to save the the x and y values of the marked point on the plot.
Can someone explain me please how to write a code or what functions can i use.
Thank you !
댓글 수: 0
채택된 답변
Scott MacKenzie
2022년 3월 12일
편집: Scott MacKenzie
2022년 3월 12일
OK, this seems to to work. The x-y coordinates of the marked points are output to the command window (along with the figure number). For brevity, I'm just showing the result for the 1st data set.
format shortg
xlsdata=xlsread('temp.xlsx'); % this is the data in your ForDataMining.xlsx file
Wavelength=xlsdata(2:2152);
for i=1:1 % first data set only, adjust as desired
reflection = xlsdata(2:2152,i+1);
lmin = islocalmin(reflection,"MinProminence",0.01,"MinSeparation",100);
% get x-y coordinates of minima
x = Wavelength(lmin)';
y = reflection(lmin);
figNumber = repmat(i, numel(x), 1);
[figNumber x y] % output in command window (include figure number)
figure(i) % put figure statement here
plot(Wavelength,reflection,Wavelength(lmin),reflection(lmin),'ro')
title('Relative Reflectance-Wavelength')
xlabel('Wavelength[nm]')
ylabel('Relative Reflectance')
grid on
grid minor
end
댓글 수: 2
추가 답변 (1개)
Scott MacKenzie
2022년 3월 12일
편집: Scott MacKenzie
2022년 3월 12일
Since you haven't provided any data or code, this is a rough answer only:
[pks, locn] = findpeaks(-y, 'MinPeakProminence', 0.1);
Using -y will give you the valleys, which is what you are after. You'll need to play with the peak prominence value to the get the valleys you want and exclude those you don't want. Then, you need to take the negative of pks to get the actual y values of the valleys. You can use locn to retrieve the corresponding x values.
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!