Getting Started with MATLAB and Live Scripts
English translation
Learning objectives
Run commands and inspect variables, then create a Live Script that records input conditions alongside results.
Execution conditions
Use MATLAB or MATLAB Online. The basic activities run in MATLAB alone and do not require a drone connection.
Check inputs and units first
Starting conditions
Start with distance .5 m and speed .25 m/s.
Procedure
- Create distance_m=0.5 and speed_mps=0.25, then calculate travel time using time_s=distance_m/speed_mps. Record the name, value, and size of the three Workspace variables.
- Run the time calculation line with and without a trailing semicolon. State whether the calculated value or the displayed output changes.
Results to retain
- A calculation example with units and a variable list.
distance_m=.5;speed_mps=.25;
travel_time_s=distance_m/speed_mps;
disp(travel_time_s);
% TODO: Document input variables and units.
Record results and self-check
Distance [m] | |
Speed [m/s] | |
Time [s] |
Points to check
- Did you store speed and time in separate variables?
- Did you compare calculated values without changing units?
Combine into a script and change conditions
Starting conditions
Change the distance from .5 to .8 m and keep the speed at .25 m/s.
Procedure
- Organize inputs, calculations, and result explanations into separate sections.
- Change only the distance, rerun, and compare the times for the two conditions.
- Run only the calculation section without defining inputs, and check which variables it depends on.
Results to retain
- A comparison of two conditions and a Live Script ordered as inputs→calculations→outputs.
distance_m=.8;
travel_time_s=distance_m/speed_mps;
fprintf('Time: %.2f s\n',travel_time_s);
% TODO: Summarize both conditions side by side.
Record results and self-check
Condition | |
Distance [m] | |
Speed [m/s] | |
Calculated time [s] |
Points to check
- Did you save input definitions as well as outputs?
- Do the modified conditions and latest output refer to the same experiment?
Use error messages to locate fixes
Starting conditions
Examine the cases of mistyping speed_mps as speed_ms and setting speed_mps=0.
Procedure
- Check the typo and division by 0 separately.
- Check that speed_mps>0 before calculating travel time.
- Run the file from the beginning and check that inputs, checks, and calculations all execute.
Results to retain
- Two types of errors and results after correction.
assert(speed_mps>0,'Speed must be positive');
travel_time_s=distance_m/speed_mps;
% TODO: Test typos and invalid inputs one at a time, then restore normal operation.
Record results and self-check
Input issue | |
Observed behavior | |
Modified location |
Points to check
- Have you distinguished typos from physically invalid values?
- Does it run without previous Workspace values?