Ability to add two variable on separate lines into a title
조회 수: 17 (최근 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에서 Title에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!