How do I display a variable in a plot title?

11 ビュー (過去 30 日間)
Cody Stein
Cody Stein 2015 年 4 月 1 日
コメント済み: Cody Stein 2015 年 4 月 2 日
So I'm working on modeling the Three Body problem in a class where we have 12 different orbits that we are looking at. Originally we had to enter in the initial conditions for each orbit twelve separate times, however I was able to utilize a for loop to get it to run all 12 at the same time. I am also able to get the program to output into the graph title whether or not the orbit it prograde or retrograde using if statements:
My question is: Is there anyway to get it so I can have the pot title also include the distance of the initial orbit? For example if one set of my initial conditions is:
Is there a way that I can get the plot title to display the last - (IC(12) - value after prograde so the plot title would say something to the effect of, "Planetary Orbit around a Binary Star System - Prograde Motion at -insert IC(12) value here- AU"?
  1 件のコメント
Stephen23
Stephen23 2015 年 4 月 1 日
What magnitude is the values, and what number formatting would you like it to have? Here are some options:
  • fixed point
  • exponential
  • with trailing zeros
  • significant figures

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

採用された回答

Stephen23
Stephen23 2015 年 4 月 1 日
編集済み: Stephen23 2015 年 4 月 1 日
Use sprintf to include any variables in a string. For example:
str = sprintf('Planetary Orbit around a Binary Star System - Prograde Motion at %f AU', IC(12));
title(str)
Note that there are many number formatting options available, including floating point, integer, exponential, significant figures, trailing zeros, +/- signs, and much more. Please read the sprintf documentation carefully and pick the best format for your application. In the example above I used '%f', which converts fixed point notation.
  1 件のコメント
Cody Stein
Cody Stein 2015 年 4 月 2 日
Thank you so much for the help! :D

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by