📄 notes.m
字号:
%NOTES
MATLAB Preliminaries
Matlab File types
Scripts are used for storing several executable statements.
Functions are used for functions and subroutines.
MAT-files are used for storing data.
Editing
The command window.
1. The command window is used for immediate mode entering and display
of variables and execution of a MATLAB command.
2. The command window is used for execution of a functions, subroutines
and programs that are stored in an M-File .
The edit window.
1. The edit window is write and edit functions, subroutines and programs
which are to be stored in an M-File.
The graph window
1. The graph window is used to view plotted data.
Diary
Diary <filename> directs output to the file
Diary off suspends the diary
Diary on turns diary on again
Conservation of resources
Most numerical experiments involve columns of numbers which might extend
several pages. It is not necessary to see all of the computations in a project.
Judicious use of diary and files commands such as X(1:5:N) will reduce the
amount of paperwork. Before you hand in a project, determine how little is required.
Obtaining Help
HELP topic gives help on the topic.
HELP word where 'word' is a filename,
displays the first comment lines in the M-file 'word.m'.
Housekeeping
; Place at the end of line to suppress the computer echo.
, Used at the end of a line if the computer echo is desired.
% This is a comment.
format short output displays four decimal places
format long output displays fourteen decimal places
who list of variables
what list of files
clear clear workspace
clear variables clear variables
clear functions clear functions
clc clear display
clg clear graph
Assignment Statements
痻 = 2;
痽 = x^2 -3*x + 2;
Form of a MATLAB Program M-File of executable statements
% <program-name>
{<specification-statements>}
{<executable-statements>}
Form of a MATLAB Subroutine M-File
function (output-list) = <subroutine-name> (argument-list)
{<specification-statements>}
{<executable-statements>}
Example, store the following subroutine in the M-file; sroot.m
function r = sroot(A)
% Newton's method to find A^(1/2)
p0 = 1; % Starting value.
for k=1:50,
p1 = (p0+A/p0)/2;
disp(p1);
if abs(p1-p0)/p1 < eps, break, end;
p0 = p1;
end
Form of a function (or subroutine) call.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -