Ability to add two variable on separate lines into a title

39 次查看(过去 30 天)
Hi all,
I've been writing some code recently to plot various results from different tests in an attempt to remove the steps in Excel of going through selecting data each time. I'm struggling, however, with adding variables onto my graph. I'd quite like to have things like ranges shown, max and min (done that), a legend plate positioned somewhere (struggling with even getting one to show) and having two variables with text and number in a title on separate lines.
Any help or comments you have on my program would be appreciated. As an addition, how do I force Matlab to then print my graphed result full page, landscape fit to something like a .pdf?
Many thanks
% Create the title for all graphs
TIT = sprintf('%s, On %s', answer{:});
wear = DiamondWear';
Width_Range = range(wear);
v = 1:1:NOC; % Create the x axis
v1 = v'; % Turn the row data into a column
vad = diff(wear);
vad1 = max(vad)
figure('units','normalized','outerposition',[0 0 1 1]);
h = plot(v1,wear,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','b',...
'MarkerSize',2);
str = sprintf('Diamond Wear Repeatability = %f mm %f', Width_Range);
%str2 = sprintf('Maximum point to point deviation = %f mm %f', vad1);
title(str,'FontSize',14);
xlabel('Measurement number','FontSize',14)
ylabel('Diamond Wear (mm)','FontSize',14)
x = get(h,'XData'); % Get the plotted data
y = get(h,'YData');
imin = find(min(y) == y); % Find the index of the min and max
imax = find(max(y) == y);
text(x(imin),y(imin),[' Minimum = ',num2str(y(imin))],...
'VerticalAlignment','middle',...
'HorizontalAlignment','left',...
'FontSize',10)
text(x(imax),y(imax),['Max = ',num2str(y(imax))],...
'VerticalAlignment','bottom',...
'HorizontalAlignment','right',...
'FontSize',10)
suptitle(TIT)

回答(2 个)

Thorsten
Thorsten 2015-3-27
title({'Peaks', int2str(2015)})
  2 个评论
Vadim Baines-Jones
Vadim Baines-Jones 2015-3-27
Hi there,
Thanks for your comment. Whilst I know how to make a title, I'm unsure how to make two on the same plot, and a supertitle. I can make the supertitle and one title but not two.
I thought something like:
str = sprintf('Diamond Wear Repeatability = %f mm %f', Width_Range);
str2 = sprintf('Maximum point to point deviation = %f mm %f', vad1);
title(str,\n,str2,'FontSize',14);
would work but it doesn't.
Thorsten
Thorsten 2015-3-27
My example was probably not clear enough. Just use
title({str, str2})
BTW: the second %f does not have any effect in your sprintf commands.
And for the second part of your question, use:
set(gcf, 'PaperOrientation', 'landscape')
print -dpdf foo.pdf

请先登录,再进行评论。


Vadim Baines-Jones
Vadim Baines-Jones 2015-3-27
Update - I found this in another section of this helpful forum! Does what I need (for the first part of the question).
title(['\fontsize{12}' str, ...
'\newline \fontsize{10} \color{red} \it' str2]);

类别

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