How can I add the percentage result on plotted figure ?

4 ビュー (過去 30 日間)
Onur Hakverdi
Onur Hakverdi 2021 年 6 月 22 日
編集済み: Walter Roberson 2021 年 6 月 24 日
Hi I have this code. Everything is fine, the code plots wavelength-intensity relationship according to the csv data and it labels the peak point. So my question is I have a formula for the percentage. It's (intensity/intensity_max)*100 so I need to add a text code that will solve the equation and it will show the result for every if and elseif state on the figure.

回答 (2 件)

Alan Stevens
Alan Stevens 2021 年 6 月 22 日
  5 件のコメント
Alan Stevens
Alan Stevens 2021 年 6 月 22 日
You have intensity values at all waveengths!
Since the first "if" section just considers intensity_max, not intensity, I guess you want to calculate
(intensity_max/345.1)*100.
If so, then do something like:
pc = (intensity_max/intensity)*100;
then after your plot command do something like
text(x,y,num2str(pc))
where you choose x and y as suitable coordinates to place the value where you want on the graph.
Onur Hakverdi
Onur Hakverdi 2021 年 6 月 22 日
my x and y coordinates are undefined so I don't know the values because it's randomly data.

サインインしてコメントする。


Steven Lord
Steven Lord 2021 年 6 月 22 日
FYI if you want the only marker to be at the highest point you could use MarkerIndices rather than plotting two separate lines.
x = 1:100;
y = 20*rand(size(x));
[~, ind] = max(y);
plot(x, y, 'o-', 'MarkerFaceColor', 'r', 'MarkerIndices', ind)
I'm not 100% sure of what you're looking for, but do you want to have lines across the plot indicating when the values are in certain ranges?
figure
plot(x, y, 'o-', 'MarkerFaceColor', 'r', 'MarkerIndices', ind)
hold on
yline(10, 'Label', 'halfway point');
yline(5, 'Label', 'quarter of the way through')
  12 件のコメント
Onur Hakverdi
Onur Hakverdi 2021 年 6 月 23 日
hi problem with the x y coordinates because my coordinates are unknown it depends the data.
Walter Roberson
Walter Roberson 2021 年 6 月 24 日
編集済み: Walter Roberson 2021 年 6 月 24 日
txt = sprintf('ratio = %.2f', (intensity/intensity_max)*100);
title(txt)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by