Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

matlab question. Question 4 (a) Write a function spellWord that accepts a string

ID: 3909726 • Letter: M

Question

matlab question.

Question 4 (a) Write a function spellWord that accepts a string and returns another string n as per examples below: spellWord('hello) will return the string "h-e-1-1-o", spellWord('tomorrow') will return "t-o-m-o-r-r-o-w". Your function should work with any string length, including the empty string. Hint: use the concatenate operation to build the string [14 marks] (b) List three string values you would use to test your function, and briefly explain why you have chosen each value. [4 marks]

Explanation / Answer

function [A3] = spellWord(A1)
A2 = repmat('-', 1,strlength(A1));
C1 = [A1; A2];
A3 = C1(1:1:end:end-1);
end

Output:

>> spellWord('helloworld')

ans =

'h-e-l-l-o-w-o-r-l-d'

>> spellWord('tomorrow')

ans =

't-o-m-o-r-r-o-w'

>>