MATLAB INTRODUCTION Below is a MATLAB script introducing you to MATLAB and giving examples of how to use the standard atmosphere function called atmosphere4. Put the contents of this file from below the ****** into a text file called test.m This file and matlab function atmosphere4 cam be found http://roger.ecn.purdue.edu/%7Eandrisan/Courses/AAE490A_S2006/Buffer/ Make sure test.m and atmosphere4.m are in the MATLAB search path. Execute the file test.m from the MATLAB command line by typing test ****** % General Introduction to MATLAB and a % script to use the MATLAB function called atmosphere4. disp('Start of the script') %This line displays in the MATLAB % Command Window the text contained within the two quote marks. % Comment lines start with a %, like this line. % Comment lines generate no output in the MATLAB % Command Window (unless echo in on). % FILE NAMES % A MATLAB command is any command that can be executed % on the MATLAB Command Window. % A MATLAB script file is a file containing MATLAB commands. % Script files can have any name as long as it ends in .m % Function file names (atmosphere4.m) must be the same as the % function name (atmosphere4) with the .m appended. % The function name is found on the first line of the % function file, i.e., % function [temp,press,rho,Hgeopvector]=atmosphere4(Hvector,GeometricFlag) % MATLAB SEARCH PATH (the search path that MATLAB uses to find files) % The function atmosphere4 must be in the MATLAB search path % in order for MATLAB to find it. If it is not in the search path % use the Set Path command in the file menu of the MATLAB Command Window. % MATLAB COMMANDS (also MATLAB functions) % The MATLAB function help will type the initial comment lines % of a file until the first blank or executable line is found. help atmosphere4 echo on % Turns echo on so that all lines are printed % before being executed. %type atmosphere4 % will type the entire file. % lines like help atmosphere4 and type atmosphere4 can also % be executed from the MATLAB command line. echo off % Turns echo off so that all lines are not % printed befor being executed. % USING FUNCTION atmosphere4 WHEN Hvector is a scalar % Altitude data (Hvector) can be a scalar, i.e. one number. Hvector=1000 %When a MATLAB line does not end with a ; the results % of the line are printed. [rowsize,columnsize]=size(Hvector) %When a MATLAB line does not end with a ; %the results of the line are printed. In the case above rowsize and % colsize are printed. GeometricFlag=0 % This means that the altitude data is in geopotential feet. [temp,press,rho,Hgeopvector]=atmosphere4(Hvector,GeometricFlag) GeometricFlag=1 % This means that the altitude data is in geometric feet. [temp,press,rho,Hgeopvector]=atmosphere4(Hvector,GeometricFlag) % USING FUNCTION atmosphere4 WHEN Hvector is a vector % Altitude data (Hvector) can be a vector, i.e. an array of numbers. Hvector=0:1000:295000; %When a MATLAB line ends with a ; the results of % the line is not printed. % The above line creates a row vector called Hvector. % it starts at value 0, ends at value 295,000 and values are incremented % from eachother by 1000. There are to many numbers to print so % the semicolen prevents printing of the line (296 numbers). [rowsize,columnsize]=size(Hvector) GeometricFlag=0 % This means that the altitude data is in geopotential feet. [temp,press,rho,Hgeopvector]=atmosphere4(Hvector,GeometricFlag); %PLOTTING plot(temp,Hgeopvector) % Try typing help plot at the MATLAB command window. xlabel('Temperature, degR') ylabel('Altitude, geopotential feet') title('1976 NASA Standard Atmosphere') text(340,55000,'Stratosphere') text(360,36089,'Tropopause') text(340,15000,'Troposphere (Beechcraft Baron B58 flys here)') whos % Lists the sizes of all variables. % TRANSPOSING VECTOR Hvector Hvector=Hvector'; % The prime means matrix transpose (i.e. interchange % the rows and the columns. This will make Hvector a column vector (296x1) % instead of a row vector(1x296). [rowsize,columnsize]=size(Hvector) GeometricFlag=0 % This means that the altitude data is in geopotential feet. [temp,press,rho,Hgeopvector]=atmosphere4(Hvector,GeometricFlag); whos % Lists the sizes of all variables. Notice how the sizes % of all the matrices have change from the last time we did the whos command. % HELP COMMANDS % If you have any questions about what a MATLAB command does % type help command,i.e. help text %help help %Note that these commands have been commented out. % Remove the % to execute them. %help %help general %The many topics you can find from the help command. %help lang %help ops