Complete the code to calculate the mean of the data array.
data = [5, 10, 15, 20, 25]; meanValue = [1](data);
The mean function calculates the average value of the data array, which is essential for understanding the central tendency in statistics.
Complete the code to calculate the standard deviation of the data array.
data = [5, 10, 15, 20, 25]; stdDev = [1](data);
The std function calculates the standard deviation, which measures how spread out the data values are from the mean.
Fix the error in the code to calculate the median of the data array.
data = [5, 10, 15, 20, 25]; medianValue = [1](data);
The correct function to calculate the median in MATLAB is median. Using 'med' will cause an error because it is not a valid function.
Fill both blanks to create a dictionary (struct) of word lengths for words longer than 3 characters.
words = {'data', 'is', 'fun', 'and', 'useful'};
lengths = struct();
for i = 1:length(words)
word = words{i};
if length(word) [1] 3
lengths.([2]) = length(word);
end
endThe condition length(word) > 3 checks for words longer than 3 characters. Using word as the field name in the struct stores the length keyed by the word itself.
Fill all three blanks to create a struct of word lengths for words with length greater than 3.
words = {'apple', 'cat', 'banana', 'dog'};
lengths = struct();
for i = 1:length(words)
word = words{i};
if length(word) [1] 3
lengths.([2]) = [3](word);
end
endThe condition length(word) > 3 selects words longer than 3 characters. The struct field is named by the word itself, and length(word) gives the number of characters.
