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)
0 个评论
回答(2 个)
Thorsten
2015-3-27
title({'Peaks', int2str(2015)})
2 个评论
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!