(MATLAB) Convert \'countem\' into a function. This function should take the inpu
ID: 3724326 • Letter: #
Question
(MATLAB) Convert 'countem' into a function. This function should take the inputs of n0 and N and display the results. Name this function 'countemF'
-Do not have clear and clc inside the function
-Write codes using only MATLAB
Setting no and N should not be done with an input command. When you turn in your code use no- 5 and N 10 as shown in the problem definition. Solution: % counten.m % Displays the values of N integers starting at n° in a well % formatted line. %% Set Variables no = 5; N = 10; nString = num2 str (no); myArray = n0; %% Create String for ix = 1:N-1 myArray (1x+1) = n0 + ix; nstring = [nString, ' , ' , num2str (myArray (ix+1) ) ] ; end disp ( [ ' nO- ' , disp (nString) num2 str (no) , ' , N = ' , num2str (N) ] ) Command Window: n0 = 5, N=10 5, 6, 7, 8, 9, 10, 11, 12, 13, 14Explanation / Answer
%%SAVE AS countemF.m
%%The function that takes no and N as input
%%arguments and print output
function y=countemF(n0,N)
%%Set Variables
nString=num2str(n0);
myArray=n0;
%%create string
for ix=1:N-1
myArray(ix+1)=n0+ix;
nString=[nString, ', ',num2str(myArray(ix+1))];
end
disp(['n0 = ',num2str(n0),', N = ',num2str(N)])
disp(nString)
end
---------------------------------------------------------------------------------------------
Sample Output :
>> countemF(5,10)
n0 = 5, N = 10
5, 6, 7, 8, 9, 10, 11, 12, 13, 14
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.