How to display a Y value

20 ビュー (過去 30 日間)
Ashley Megow
Ashley Megow 2020 年 10 月 30 日
回答済み: Peter O 2020 年 10 月 30 日
I ploted a line graph with two different lines. I wish to enter a specific x value and display both y values, based on points from the graph. X being YEAR, and the y values being MALE and FEMALE.
  3 件のコメント
Ashley Megow
Ashley Megow 2020 年 10 月 30 日
if the user were to input the YEAR as 1990, then the values of MALE and FEMALE from the graph would be displayed in the command window.
Ashley Megow
Ashley Megow 2020 年 10 月 30 日
I have a table that I imported, so I would like it to take the number I inputed, and display the two y values it has.
I would like the user to enter the YEAR and then the values from this chart for male and female to be displayed

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

採用された回答

Peter O
Peter O 2020 年 10 月 30 日
For interactive use of the graph, consider use of the datatips functionality. In R2018 and above, if you hover your cursor over the year/point of interest and click, you'll see a datatip show up with the info you want. For earlier releases, there's a toolbar button called "Datatips" that you can switch on to make the cursor do the same thing. You can drag it around to different values or switch between plots.
There's a picture about halfway down: https://www.mathworks.com/help/matlab/ref/matlab.graphics.datatip.datatip.html
If you really want an access/report function, consider something like the function below. You'd have to call it each time and pass in the data from the plot. The first argument is the year of interest, followed by the data.
function reportVal(year, YearVals, MaleVals, FemaleVals)
ix = find(YearVals == year);
if ~isempty(ix)
M = MaleVals(ix);
F = FemaleVals(ix);
fprintf('Year: %u\n', yr);
fprintf('Female: %8.5f\n',F);
fprintf('Male: %8.5f\n',M);
else
fprintf('Year not found.\n')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by