This series is a study note for quickly getting started with MATLAB, aimed at recording the learning process for future reference. I am honored if it can help you. Practicing the Feynman learning method, I openly share and welcome communication and corrections!
Friendly Reminder: The content density of this article is comparable to that of concentrated coffee ☕️, it is recommended to operate synchronously with the MATLAB interface! The previous article unlocked learning materials and operational skills, while this one will take you to experience the speed thrill of MATLAB—solving the hardest problems with the most stylish operations!
📚 Resource Map for the Entire Series
| Title | Core Skills | Application Scenarios |
|---|---|---|
| Quick Start to MATLAB 01 | Environment Configuration | Genuine Usage Plan |
| Quick Start to MATLAB 02 | Learning Path | Official Documentation Guide |
Operating MATLAB is like LEGO blocks—using the right basic modules, complex models can be built in seconds! Most content has already been packaged, just call it directly. Below are the four core operations:
1. Initial Exploration of the Environment: Your Digital Laboratory
1.1 Command Window: The Calculator at Your Service
>> 2+3*sin(pi/2) % Input and calculate (press Enter to execute), ending with a semicolon will not display the result
ans = 5 % The result is automatically stored as the variable ans
>> cosd(60) % Angle calculation function (note the d suffix)
ans = 0.5000
Is this simpler than a mobile calculator? That’s right! But what’s cooler is—pressing the
<span>↑</span>key can summon historical commands.
1.2 Workspace: The Variable Zoo Keeper
| Operation | Code Example | Effect |
|---|---|---|
| Create Variable | <span>x = [1,3,5]</span> |
Row vector<span>[1 3 5]</span> |
| View Variables | <span>whos</span> |
Display all variable information |
| Delete Variable | <span>clear x</span> |
Release variable x |
| Save Zoo | <span>save data.mat</span> |
Package all variables |
Avoid using function names like
<span>cos</span>/<span>sin</span>as variable names! Otherwise, you will encounter the error of “The Ethical Drama of Variables and Functions”.
2. Matrix Operations: LEGO Blocks for Data Processing
2.1 Matrix Creation: From Bronze to King
% Bronze: Manual input
A = [1,2,3; 4,5,6; 7,8,9] % 3x3 matrix
% Silver: Automatic generation
B = zeros(2,4) % 2 rows 4 columns zero matrix
C = ones(3) % 3rd order full 1 matrix
D = eye(4) % 4th order identity matrix (diagonal is 1)
% King: Advanced play
E = linspace(0,10,5) % 5 equal segments from 0 to 10 → [0,2.5,5,7.5,10]
F = rand(3,2) % 3 rows 2 columns random matrix (uniform distribution from 0 to 1)
<span>linspace</span>is like cutting a cake 🍰—specifying the start and end points and the number of pieces, MATLAB will cut it neatly for you!