In this topic, commands and functions required to use MATLAB software easily at the beginning will be given.
Until now, in our applications made using MATLAB, we were executing the commands or functions required to perform a certain operation by entering one by one after the >> symbols from the command line. Whereas, we can save a special group related to a job we want to perform from MATLAB commands or functions in a file and execute it by calling this filename.
A file of this type containing a group of statements or commands is called an M-file (M-File) in MATLAB. It is a program file by definition because it contains a command group. So programming is will be done by creating M-files.
-- If "helpwin" command is entered on the command line or if the "Help Window" option is selected from the Help menu of MATLAB, information about the desired topic can be obtained from the help options that will appear.
-- Creating "M-File": The programming process is done in M-File (Program File) files. For this reason, the process that will be used the most while writing a program is creating an M-File. For this, select "New" from the "File" menu and then select the "M-File" option. Thus, a new programming screen is obtained. After the programming is completed, select the "Save As" option from the "File" menu of the "M-File" file. The written program will be saved in the work file with the desired name. The extension of the recorded files will be saved as .m. (Example: result.m) In order to run the desired file, it is sufficient to type the file name on the command line and press the "Enter" key. It can also be run from the "work" menu.
A) General Commands
-- workspace Command: During the study, detailed information about the variables available in the workspace (memory allocated to the user) is given in a window as shown below. By double clicking on the variables in the window, information about that variable can be accessed and changes can be made.
B) Variable Assignment
In programming languages such as "C" and "PASCAL", just before starting the creation of the main body of the program, it is necessary to specify which type of variables all the variables in the program are, and to make sure that the program allocates the appropriate amount of space for these variables from the computer memory. In MATLAB, variables are created with the help of their own name and the values to be assigned to them. Without specifying the variable type beforehand, depending on the value given to the variable, MATLAB determines the right variable type and allocates enough space from the computer memory to this variable. In the first chapter, some information about basic assignments (constant, variable, matrix, array, vector definition ...) was given.
C) Creating A Function And The Other Commands:
-- sum( ), min( ), max( ), mean( ) Commands: The commands on the side find the sum of the elements of a vector, its smallest element, largest element and average, respectively.
D) Loops And If Practises:
1. Conditional Expressions :
-- if Structure: There are three different variations of the "if" command in MatLab :
a) if
statement1
statement2
statement_n
end
If the condition is true, it runs statement1, statement2, ... , statement_n, and finally the "end" parameter takes the control of program ; If the condition is false, then statement 1, statement 2, ..., statement will pass to the statement after the control end without executing the group of statements specified with n.
2. Loop Expressions :
-- for Loop: The parameter value is changed starting from the initial level and increasing by the increment value each time until the last value is reached. For each value of the parameter, the group of statements specified in the form of statement1, statement2, statement_n and included between the words for-end is executed. When the value of the parameter exceeds the last value, the control of the program will go out of the loop, to the statement following the "end".
"*"
Source: https://www.turkhackteam.org/matlab/1941245-matlab-ile-programlama.html
Translator: Dolyetyus
Moderatör tarafında düzenlendi: