Is it possible to plot the data and show two different scales for the same data using MATLAB 7.9 (R2009b)?

12 ビュー (過去 30 日間)
I want to plot some data and show two different scales for the Y-axis. For example, the data I have plotted is in inches (for Y-axis, displayed on the left side) and I wish to show the equivalent scale in centimeters on the right side of the axis.

採用された回答

MathWorks Support Team
MathWorks Support Team 2010 年 3 月 9 日
It is possible to create a new scale that may be corresponding to the scale on the left side (Y-axis) and display it on the right side of the axis. Please follow the example below which demonstrates one way of how this may be done.
% Create data for demonstration
x = 0:0.01:20;
y = 200*exp(-0.05*x).*sin(x); % Assuming result is in inches
% Plot the results
f = figure;
a1 = axes;
plot(x,y)
% Query the YTicks
yt = get(a1,'YTick');
% Create a new axis based on the existing axis
a2 = copyobj(a1,f);
% Make the new axis transparent
set(a2,'Color','none')
% Remove the XTicks (since they are redundant)
set(a2,'Xtick',[])
% Display the YTicks on the right side
set(a2,'YAxisLocation','right')
% Convert the YTick values based on a different scale
% In this case we are converting inches into centimeters
converted_values = 2.54*yt;
% Use essentially the same ticks but update the labels
set(a2,'YTickLabel',converted_values)
% Label your plot appropriately
xlabel(a1,'X [units]')
ylabel(a1,'Y [inches]')
ylabel(a2,'Y [cms]')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

タグ

製品


リリース

R2009b

Community Treasure Hunt

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

Start Hunting!

Translated by