Code covered by the BSD License  

Highlights from
addaxis_unit

image thumbnail
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
function addaxis_unit_example_hAxes
%Example if handle is axes

clear 
close all

%% Artificial Data
x = 0:10;
y1a = x;
y1b = x;
y2a_ticks = [0 10 20 30 40 50 60 70 80 90 100]';
y2b_ticks = [0 1 2 3 4 5]';

%% 1. Example Plot with common Matlab function
figure(1)
subplot(2,1,1)
plot(x,y1a)
xlabel('x')
ylabel('y1a')
addaxis_unit(gca,@fa_common_Matlab,y2a_ticks,'y2b = y1a^2')

subplot(2,1,2)
plot(x,y1b)
xlabel('x')
ylabel('y1b')
addaxis_unit(gca,@fb_common_Matlab,y2b_ticks,'y2b = sqrt(y1b)')

function y1a = fa_common_Matlab(y2a)
%common Matlab function
y1a = sqrt(y2a);


function y1b = fb_common_Matlab(y2b)
%common Matlab function
y1b = y2b.^2;

Contact us at files@mathworks.com