Question

4. Create a function, which takes as input a string and a letter. Determine whether or...

4. Create a function, which takes as input a string and a letter. Determine whether or not the letter is present in the string. The function should return a logical true/false if the given letter is present/absent. HINT: use find and isempty.

Please anyone helping me with this question can you code using Matlab software, please.

Homework Answers

Answer #1

MATLAB Script:

close all
clear
clc

% Example function calls
result1 = findLetter('ayAzAb', 'a');
result2 = findLetter('ayAzAb', 'b');
result3 = findLetter('ayAzAb', 'B');
result4 = findLetter('ayAAb', 'z');

function found = findLetter(text, letter)
found = ~isempty(find(text == letter, 1));
if found
fprintf('Letter %c is present in the string %s\n', letter, text)
else
fprintf('Letter %c is not present in the string %s\n', letter, text)
end
end

Example Outputs:

Letter a is present in the string ayAzAb
Letter b is present in the string ayAzAb
Letter B is not present in the string ayAzAb
Letter z is not present in the string ayAAb

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a function in MIPS using MARS to determine whether a user input string is a...
Create a function in MIPS using MARS to determine whether a user input string is a palindrome or not. Assume that the function is not part of the same program that is calling it. This means it would not have access to your .data segment in the function, so you need to send and receive information from the function itself. The program should be as simple as possible while still using necessary procedures. Follow the instructions below carefully. Instructions: ●...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and integer as a parameter. Your function should truncate the string by placing a NULL byte at the specified index. You should return the index passed as a parameter if successful, -1 on fail. For example, if the index given is 5, but the string is “fun”, you would return -1 because the string is not long enough.
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and...
3. Write function, leastChar(inputString) that takes as input a string of one or more letters (and no other characters) and prints 1) the "least" character in the string, where one character is less than another if it occurs earlier in the alphabet (thus 'a' is less than 'C' and both are less than 'y') and 2) the index of the first occurrence of that character. When comparing letters in this problem, ignore case - i.e. 'e' and 'E' should be...
create a program in c++ to determine whether any 5-letter word is a palindrome. Palindromes are...
create a program in c++ to determine whether any 5-letter word is a palindrome. Palindromes are words or sentences that read the same backward or forward. For example, “kayak” is a palindrome while “meter” is not. Ask the user to input 5 characters. You will need five separate variables to store these five characters. After obtaining the characters, compare the characters to determine if the word is a palindrome and output an appropriate message. Ex: Please enter 5 letters: h...
Write the function decipher(s, frequencies), which will decipher a Caesar cipher encrypted string s using the...
Write the function decipher(s, frequencies), which will decipher a Caesar cipher encrypted string s using the letter frequencies in frequencies, and return the plaintext string. Here is a sample of how this function would be used: if __name__ == '__main__': # this file path works on my computer. # you will need to set this path to work on your computer! f = open('/Users/azs/code/bu/cs108/assignments/romeo.txt') text = f.read() f.close() d = letter_frequencies(text) s1 = 'h svun aptl h nv pu h...
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function....
Using c++ Valid Palindrome In this assignment, you need to implement a bool isPalindrome(string s) function. Given a string s, isPalindrome(s) can determine if s is a palindrome, considering only alphanumeric characters and ignoring cases. Note: for the purpose of this problem, we define empty string as valid palindrome. Example 1: Input: ”A man, a plan, a canal: Panama” Output: true Example 2: Input: ”race a car” Output: false Requirement: There are many methods to check if a string is...
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
In this Java programming assignment, you will practice using selection statements to determine whether a given...
In this Java programming assignment, you will practice using selection statements to determine whether a given year in the past or future qualifies as a “Leap Year”. I. Design a class called LeapYear in a file called LeapYear.java. This class will hold the main method and the class method that we will write in this assignment. II. Write an empty public static void main(String[] args) method. This method should appear inside the curly braces of the LeapYear class. III. Write...
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100...
(a) Write an algorithm (use pseudo-code) to determine whether a function f ∶ Z100 → Z100 is surjective. That is, supply a “Method” to go with Input: A function (array) f with f(i) ∈ Z100 for i = 0, 1, . . . , 99. Output: Boolean B. B=‘true’ if f is surjective, ‘false’ otherwise. Try to make your algorithm as efficient as possible. Do NOT include an implementation of your algorithm in a programming language. (b) How many comparisons...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT