Error using sgtitle?

조회 수: 25 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by