2.1 MATLABC BREAKN DIGIT Your task is to develop a user-defined function entitle
ID: 3568517 • Letter: 2
Question
2.1 MATLABC BREAKN DIGIT Your task is to develop a user-defined function entitled breakN2digits here the objective of the function i s to take an integer input and output an array containing all of the input integer's digit components. Each digit should be allocated to an index within an output array. The function should work for any sized integer in MATL C. You are limited to only zeros() & numel for MATLABO uilt-in functions. Report th using three different sized positive gers. When developing y our function e output inte start with the following fra and articulate th e output as shown in th e example function loutputArray l breakN2 digits (input Integer) An example execution and output is provided below input Integer 9876 solution array breakN2digits input Integer) solution arrayExplanation / Answer
function [outputArray] = breakN2digits(inputInteger)
temp = inputInteger;
size = 0;
while temp > 1.0
size++;
temp = (temp/10);
i=0;
while i< temp
i=i+1;
end
i = i-1;
end
outputArray = zeros(1, size);
t = inputInteger;
for j=numel(outputArray):-1:1
t=(t/10);
i=0;
while i< t
i=i+1;
end
i = i-1;
outputArray(j) = inputInteger - i*10;
inputInteger = i;
end
end
inputInteger=9876;
solution_array = breakN2digits(inputInteger)
------------------------------------------------------
OUTPUT
solution_array =
9 8 7 6
-----------------------------------
inputInteger=114455;
solution_array = breakN2digits(inputInteger)
solution_array =
1 1 4 4 5 5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.