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.
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
Get Answers For Free
Most questions answered within 1 hours.