Write a Matlab program with the function islandid to enter a first name, middle
ID: 3716471 • Letter: W
Question
Write a Matlab program with the function islandid to enter a first name, middle name and last name in separate variables.
After entering each name at the keyboard, call a function named convert that will capitalize the first letter of the name and set the rest of the name to lowercase (for example, jOhN becomesJohn). The convertfunction will be called three times-- once for the first name, once for the middle name, and once for the last name.
Combine the properly capitalized names into one string and output the string (make sure you have a space between each part of the name). Count the number of characters in the total name (including spaces between names) and output that total also.
Include descriptive comments in your source code.
Explanation / Answer
test.m
clc;
clear;
prompt = 'Enter your first name: ';
firstName= input(prompt,'s');
firstName = convertfunction(firstName);
prompt = 'Enter your middle name: ';
middleName= input(prompt,'s');
middleName = convertfunction(middleName);
prompt = 'Enter your last name: ';
lastName= input(prompt,'s');
lastName = convertfunction(lastName);
firstName = [firstName ' ' middleName ' ' lastName];
firstName
length(firstName)?
convertfunction.m
function name = convertfunction(name)
name = lower(name);
idx=regexp([' ' name],'(?<=s+)S','start')-1;
name(idx)=upper(name(idx));
end?
**Comment for any further queries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.