7.14: Chapter Exercises

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    Read aloud

    How

    Speed: 1×
    Light up
    Highlight

    Symbols: Mulberry Symbols, © 2018–2026 Steve Lee, CC BY-SA 4.0 (licence, the set), the site's own copies.

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    7.14: Chapter Exercises

    Exercise 1: Vector Maker

    Write a script named vectorMaker that uses a loop to prompt the user to enter elements of a vector one at a time. If the user enters any letter, the program stops and prints the vector. If the user never enters a number, display a helpful message.

    Exercise 2: Whitespace Counter

    Write a function named whitespaceCounter that receives a string scalar and returns the number of whitespace characters. Your function must use isstrprop.

    Exercise 3: Guest List

    Write a function named isGuest that receives a name and a string array containing a guest list. The function should return one logical value indicating whether the name appears on the list. The comparison should ignore case.

    Exercise 4: Split a Date

    Write a function named splitDate that receives a date in a format such as 07-Feb-2008 and returns the day, month, and year as separate output arguments.

    Exercise 5: Assembly Operation

    Write a function named assemblyOperation that receives a string in one of the following forms: "Add n,m", "Subtract n,m", "Divide n,m", or "Multiply n,m". The function should return the result of the requested operation.

    Exercise 6: Hidden Message

    In cryptography, the intended message may consist of the first letter of every word in a sentence. Write a function named crypt that receives a character vector and returns the hidden message formed from the first letter of each word.

    Exercise 7: Delete Multiple Blanks

    Write a function named deleteMultipleBlanks that receives a string containing a sentence with extra blank spaces between some words. Return the sentence with only one blank space between words.

    Exercise 8: Sine Calculator

    Write a script named sine.m that prompts the user to enter an angle followed by r for radians or d for degrees. The script should use sin for radians and sind for degrees, then display the result.

    Exercise 9: Username Cleaner

    Write a function that receives a user name as text, removes leading and trailing spaces, converts it to lowercase, and replaces internal spaces with underscores.

    Exercise 10: Simple Password Checker

    Write a function that receives a password as text and checks whether it contains at least one uppercase letter, one lowercase letter, and one digit. Use isstrprop to help with the checks.


    This page titled 7.14: Chapter Exercises was last modified on Tue, 30 Jun 2026 02:11:21 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.