from
addaxis_unit
by Friedhelm Steinhilber
This function adds a second y-axis to a x-y plot using a relationship between the two y-axes.
|
| addaxis_unit_example_hAxes_y1ticks |
function addaxis_unit_example_hAxes_y1ticks
%Example if handle is axes (subplots can be used) and y2ticklabels are
%calculated at the positions of the ticks of the first y-axis
clear
close all
%% Artificial Data
x = 0:10;
y1a = x;
y1b = x;
y2a_ticks = 'y1';
y2b_ticks = 'y1';
%% 1. Example Plot with common Matlab function
addaxis_unit('reset') % for automatic ticklabeling, when figure is resized
figure(1)
subplot(2,1,1)
plot(x,y1a)
xlabel('x')
ylabel('y1a')
addaxis_unit(gca,@fa_common_Matlab,'y1','y2b = y1a^2')
subplot(2,1,2)
plot(x,y1b)
xlabel('x')
ylabel('y1b')
addaxis_unit(gca,@fb_common_Matlab,'y1','y2b = sqrt(y1b)')
function y2a = fa_common_Matlab(y1a)
%common Matlab function
y2a = y1a.^2;
function y2b = fb_common_Matlab(y1b)
%common Matlab function
y2b = sqrt(y1b);
|
|
Contact us at files@mathworks.com