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

using Matlab to solve this gume user ipie ui a lunction that doeso ents, but in

ID: 3586327 • Letter: U

Question

      using Matlab to solve this

gume user ipie ui a lunction that doeso ents, but in this case, it does return a value. The i for a str stringprompt.m function outstr = stringp rompt rompt prompts for a string and returns it stringpr t Pormat stringprompt or stringprompt ) When prompted, enter a string of any length. ) disp( outstr = input ( Enter the string here: ' , 's') ; end >>mystring stringprompt When prompted, enter a string of any length. Enter the string here: Hi there mystring - Hi there PRACTICE 6.3 Write a function that will prompt the user for a string of at least one character, loop to error-check to make sure that the string has at least one character and return the string

Explanation / Answer

function outstr = stringprompt()
disp('When prompted, enter a string of any length.');
n=0;
while n==0%loop runs until string with at least one char is entered
outstr = input('Enter the string here: ','s');
n=length(outstr)
end
end

output:

When prompted, enter a string of any length.
Enter the string here:

n =

0

Enter the string here:

n =

0

Enter the string here: hello

n =

5


ans =

hello

>>