9.6.1: Populating an array with a for loop. This activity uses a party app Thoug
ID: 3790659 • Letter: 9
Question
9.6.1: Populating an array with a for loop. This activity uses a party app Though your actity may be recorded a remesh maybe Populating an array with a for loop write a for loop to populate munplcationTable with the multiples of basevalue trom01o 5. Ex Itbasevalueis 2,then multiplication Table is I0, 2.4, 6.8, 10W (2x0 0,2x1. 2. 2x2 4, 2x3-6, 2x4-8, 2x5 10) Your Solution HI save C Reset MATLAB Documentation 1 function multiplicationTable CreateTable(basevalue 2 Multiples of basevalue used to populate multiplicationTable nultiplicationTable zeros(1, 6 Preallocate multiplication Table with 6 elenents 5 for i e:5 multiplicationTable i base value; s write a for loop to populate nultiplicationTable with the multiples of basevalue fron e to 5 Run Your Solution Code to call your function when you click RunExplanation / Answer
% matlab code
function multiplicationTable = CreateTable(baseValue)
multiplicationTable = zeros(1,6);
for i=1:6
multiplicationTable(i) = (i-1)*baseValue;
end
end
CreateTable(2)
%output: 0 2 4 6 8 10
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.