Ability to add two variable on separate lines into a title
34 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Thorsten
on 27 Mar 2015
title({'Peaks', int2str(2015)})
2 Comments
Thorsten
on 27 Mar 2015
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
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!