In: Computer Science
Can you show how to do this step by step using Matlab please.
Write a function with header [S] = myAddString(S1, S2), where S is the concatenation of the stings S1 and S2.
Test Cases: S = myAddString(myAddString('Programming', ' '), myAddString(' is ', 'fun! '))
S = Programming is fun!
We are providing the step by step formulation first. Finally we will consolidate the entire script and run for the test case given.
1) Function header
- function [S] = myAddString(S1, S2)
- Here the input is S1,S2
- Output is concatenated S
2) concatenation, we can do this using inbuilt function and generic approach as well. We will follow the generic approach:
Example: if two strings are a='AB' and b='CD', then to
concatenate them we will do
c = [a,b]--> this will return the output string 'ABCD' in the
c.
Thus for our program, we will do the following:
S = [S1,S2];
3) And that's it, we end the function script with an
'end'
end
The total compiled script is:
%===================================
function [S] = myAddString(S1, S2)
S = [S1,S2];
end
%===================================
Note: The function script must be saved with the filename same as that of the function's name
Please find the run of the program as executed in the MATLAB as the following:
Hope this helps!
***************** PLEASE THUMBS UP!!!!!!!!!!!!!!!!!! *****************