%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% File:         uebung_inout_e.m
%
% Description:  Exercise for MATLAB Simulink 
%               MATLAB Input and Output
%
% Date:         31.03.12
% Author:       Ulrich Wohlfarth
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

echo off;
format compact;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Import and export of data 
a = (-3:1:3)'                            % a)
b = 10.^a                                    
                                             
save aundb                               % b)
                                             
clear                                    % c)
                                             
load aundb a                             % d)
                                             
save aundb.txt a  -ascii                 % e)
                                             
clear a                                  % f)
whos                                         
                                             
load aundb.txt                           % g)
whos                                         
                                             
load aundb                               % h)
whos                                         
                                             
ab = [ a b ]                             % i)
save aundb.txt ab -ascii 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Twodimensional graphics 1

w = (0:5)'                               % a) 
                                                                     
evonw = [ exp(-w) -exp(-w) ]             % b) 
                                                                     
plot(w,evonw)                            % c) 
title('Matrix evonw')                    %    
                                              
save evonw.txt -ascii                    % d) 
                                              
type evonw.txt                           % e) 
                                              
evonw1 = [w evonw]                       % f) 
                                              
save evonw1.txt evonw1 -ascii -double    % g) 
                                              
clear                                    % h)   
                                              
load evonw1.txt                          % i) 
                                              
whos                                     % j) 
evonw1                                   %    
                                          
plot(evonw1(:,2:3))                      % k) 
                                              
print -depsc evonw1.eps                  % l) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Twodimensional graphics 2
w = (-2:0.5:2)'                         % a) 
                                             
ceil(w)                                 % b) 
                                             
[w ceil(w)]                             % c) 
                                             
stairs(w,ceil(w),'r')                   % d) 
hold on                                 %    
                                             
fplot('ceil',[-2,2],'--')               % f) 
                                             
fplot('floor',[-2,2],'g-.')             % g) 
           
legend('stair(ceil)','fplot(ceil)','fplot(floor)','best') % h) 
                                           
print -depsc ceil.eps                   % i) 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Threedimensional graphics  

t = pi*(-6:0.1:6);

figure
hold on
view(3)    
axis([ min(t) max(t) min(t) max(t) min(t) max(t) ]);
for i=t ,
    if i<0, 
        plot3(sin(i).*i,cos(i).*i,i,'r+')
    elseif i==0, 
        plot3(sin(i).*i,cos(i).*i,i,'ko')
    else s='bx'; 
        plot3(sin(i).*i,cos(i).*i,i,'b*')
    end;
    pause(0.05)
end

% sophisticated
for i=t ,
    if i<0, s='r+'; elseif i==0, s='ko'; else s='b*'; end;
    plot3(sin(i).*i,cos(i).*i,i,s)
    pause(0.05)
end
plot3(sin(t).*t,cos(t).*t,t,'m')
