Error using sgtitle?

15 ビュー (過去 30 日間)
Kristin Aldridge
Kristin Aldridge 2021 年 12 月 5 日
回答済み: Walter Roberson 2021 年 12 月 5 日
I have a subplot with four graphs I'm trying to put my figures title over..
sgtitle('Mean Times per Group',['Over 37.5 = ' num2str(meanover) 'Under 37.5 = ' num2str(meanunder)]);
It accepts the "Mean Times per Group" part but gives me the error below.
Error using matlab.graphics.illustration.subplot.Text/set
Unrecognized property Over 37.5 = 0.97049Under 37.5 = 0.99391 for class Text.
Error in sgtitle (line 98)
set(h, pvpairs{:});
Any ideas why?

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 5 日
So if you have exactly two arguments like you do, the first one would have to be target . But 'Mean Times per Group' is not a target. So sgtitle() keeps parsing to figure out what the parameters are.
The next possibility is that the second parameter is one of the permitted Name options. But it is not -- there is no parameter named 'Over 37.5 = 0.97049Under 37.5 = 0.99391' .
What you probably want is
sgtitle({'Mean Times per Group',['Over 37.5 = ' num2str(meanover) 'Under 37.5 = ' num2str(meanunder)]});
Reminder though that you can code that more clealy as
sgtitle({'Mean Times per Group', "Over 37.5 = " + meanover + "Under 37.5 = " + meanunder});

その他の回答 (1 件)

Voss
Voss 2021 年 12 月 5 日
sgtitle is interpreting the second argument you give it (i.e., ['Over 37.5 = ' num2str(meanover) 'Under 37.5 = ' num2str(meanunder)]) as a property name. That is, it expects property-value pairs after the first argument, in this case.
I don't have access to sgtitle, so I can't say for sure what the solution is, but you can try sending a cell array of character arrays as the first argument, if this is meant to be a two-line title. Like this:
sgtitle({'Mean Times per Group',['Over 37.5 = ' num2str(meanover) 'Under 37.5 = ' num2str(meanunder)]});
Or if that doesn't work, you can send a character array with a newline in it, like this:
sgtitle(sprintf('Mean Times per Group\n%s',['Over 37.5 = ' num2str(meanover) 'Under 37.5 = ' num2str(meanunder)]));

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by