Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: same figure window, different scales
Replies: 1   Last Post: Mar 22, 2013 8:02 AM

 Messages: [ Previous | Next ]
 Saravanan Mani Posts: 78 Registered: 6/3/11
Re: same figure window, different scales
Posted: Mar 22, 2013 8:02 AM

"Alex " <blue.harvest.83@gmail.com> wrote in message <kigpvo\$fpk\$1@newscl01ah.mathworks.com>...
> I have a code where I need to show 3 plots on the same figure, but one is so small, that it looks like a line running along the bottom.
>
> Is there a way to have 2 scales in one window so that I can plot my 2 similar plots on a scale , and my smaller plot with a second scale?
>
> Code below if you want to see for yourself, the blue one needs to be scaled in the first window.
>
> thanks all,
> Alex
>
>
>
>
>
> close all
> clear all
> clc
>
>
> L1 = 0.001; % lambda 1
> L2 = 0.5; % lambda 2
>
> N0 = 1E12; % initial number of atoms of first nuclide
> O0 = 0; % initial number of atoms of second nuclide
> P0 = 0; % initial number of atoms of third nuclide
>
>
> Ts = [3600/923, 3600/900, 3600/897]; % time steps
>
> for a = 1:length(Ts)
>
> T = 0:Ts(a):3600; % array of times for calculation
>
> N = zeros(length(T),1); % initializing space for first nuclide
> O = zeros(length(T),1); % initializing space for second nuclide
> P = zeros(length(T),1); % initializing space for third nuclide
>
> N(1) = N0; % setting initial count in place 1
> O(1) = O0;
> P(1) = P0;
>
> for i = 1:length(T)-1
> N(i+1) = N(i) - L1*N(i)*Ts(a);
> O(i+1) = O(i) + L1*N(i)*Ts(a) - L2*O(i)*Ts(a);
> P(i+1) = P(i) + L2*O(i)*Ts(a);
> end
>
> figure % will generate new figure for each time step used
> hold on % plotting all in the same figure window
> plot(T,N,'r') % plot first decay in red
> plot(T,O,'b') % plot second decay in blue
> plot(T,P,'g') % plot third decay in green
> if a == 1
> title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
> 'Using Euler Method with Time Step 3.9 sec.'));
> elseif a == 2
> title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
> 'Using Euler Method with Time Step 4 sec.'));
> elseif a == 3
> title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
> 'Using Euler Method with Time Step 4.01 sec.'));
> else
> title('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3 Using Euler Method')
> end
>
> xlabel('Time (s)')
> ylabel('Number of Atoms')
> legend('N1', 'N2', 'N3')
> end

Hello Alex,

We can use 'subplot' concept to plot many plot in same figure window.
And if you want to specify particular position you can use 'axis' command will help you.

close all
clear all
clc
L1 = 0.001; % lambda 1
L2 = 0.5; % lambda 2

N0 = 1E12; % initial number of atoms of first nuclide
O0 = 0; % initial number of atoms of second nuclide
P0 = 0; % initial number of atoms of third nuclide
Ts = [3600/923, 3600/900, 3600/897]; % time steps
for a = 1:length(Ts)
T = 0:Ts(a):3600; % array of times for calculation
N = zeros(length(T),1); % initializing space for first nuclide
O = zeros(length(T),1); % initializing space for second nuclide
P = zeros(length(T),1); % initializing space for third nuclide
N(1) = N0; % setting initial count in place 1
O(1) = O0;
P(1) = P0;
for i = 1:length(T)-1
N(i+1) = N(i) - L1*N(i)*Ts(a);
O(i+1) = O(i) + L1*N(i)*Ts(a) - L2*O(i)*Ts(a);
P(i+1) = P(i) + L2*O(i)*Ts(a);
end
if a == 1
subplot(2,2,1)
plot(T,N,'r',T,O,'b',T,P,'g')
title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
'Using Euler Method with Time Step 3.9 sec.'));
elseif a == 2
subplot(2,2,2)
plot(T,N,'r',T,O,'b',T,P,'g')
title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
'Using Euler Method with Time Step 4 sec.'));
elseif a == 3
subplot(2,2,3)
plot(T,N,'r',T,O,'b',T,P,'g')
title(char('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3',...
'Using Euler Method with Time Step 4.01 sec.'));
else
title('Behavior of the Radioactive Decay Chain N1 -> N2 -> N3 Using Euler Method')
end

xlabel('Time (s)')
ylabel('Number of Atoms')
legend('N1', 'N2', 'N3')
end

Best Regards,
Saravanan Mani

Date Subject Author
3/22/13 Alex
3/22/13 Saravanan Mani