MATLAB Vectors and Sensor Data
English translation
Learning objectives
Combine time, height, and battery records into an array, then select and inspect the intervals and conditions you need.
Execution conditions
Use MATLAB or MATLAB Online. The basic activities run in MATLAB alone and do not require a drone connection.
Convert a measurement table to an array
Starting conditions
Use the example's time, height, and battery columns.
Procedure
- Create three column vectors and combine them into a 5×3 array.
- Use size to check the dimensions, and extract the third row and the height column separately.
Results to retain
- Row/column selection results and a measurement table with units.
t=(0:4)';height_m=[0;.4;.9;.7;.1];battery_pct=[92;91;90;89;88];
measurements=[t,height_m,battery_pct];
disp(size(measurements));disp(measurements(3,:));
% TODO: Select the height column and compare with row selection.
Record results and self-check
Selection method | |
Array size | |
Meaning of values |
Points to check
- Did you place the three values at each time in the same row?
- Have you distinguished index 3 from time 3 seconds?
Select by height condition and time interval
Starting conditions
Select height≥.5 m and 1≤t≤3 seconds separately.
Procedure
- Create two logical arrays and check which rows are selected.
- Select records that satisfy both conditions, and record time, height, and battery together.
- Change the height condition to .8 m and check which rows are excluded.
Results to retain
- Selection results for each condition and selected points marked on a height plot.
above=height_m>=.5;
in_window=t>=1 & t<=3;
disp(measurements(above & in_window,:));
% TODO: Add the .8 m condition and mark the selected points.
Record results and self-check
Condition | |
Selected times [s] | |
Height [m] | |
Battery [%] |
Points to check
- Have you avoided incorrectly mixing separate height and time criteria?
- Are column meanings preserved when conditions change?
Handle empty selection results
Starting conditions
No records satisfy height≥2 m.
Procedure
- Select rows with height at least 2 m, and record the results of size and isempty. If no heights are selected, branch to display 'No results' instead of the maximum.
- Before running the selection code, append one value to each column vector t, height_m, and battery_pct, then rerun measurements=[t,height_m,battery_pct]. The new elements of all three vectors must form the same measurement row. Set the added row's height to at least 2 m and record the three values.
- Rerun the same selection code and record the selected row count, displayed result, and maximum selected height before and after the addition, side by side.
Results to retain
- Empty results and results after adding a new measurement.
selected=measurements(height_m>=2,:);
disp(size(selected));disp(isempty(selected));
% TODO: Handle empty results and new measurements.
Record results and self-check
Condition | |
Number of rows | |
Subsequent calculation/display |
Points to check
- Have you avoided replacing an empty array with an actual height of 0?
- Can the added row be included without manually changing the number 5 in the code?