To create:
The length of the character vector and also its first and last characters.
Answer to Problem 7.1P
Solution:
The script is saved and executed as follows.
Explanation of Solution
MATLAB Code:
clc
clear all
close all
string = input('Enter a string: ','s');
%Define the instruction to enter a string.
fprintf('The number of character used in a string: %d\n', length(string))
%Define the length of the string.
fprintf('The first character used in the input string is: %s\n', string(1))
%Define the instruction to print the first character of the input string.
fprintf('The last character used in the input string is: %s\n', string(end))
%Define the instruction to print the last character of the input string.
Save the MATLAB script with name, chapter_7_54793_7_1P.m in the current folder. Execute the script by typing the string name at the command window to create the length of the character vector and also its first and last characters.
Result:
Therefore, the script is saved and executed.
Want to see more full solutions like this?
Chapter 7 Solutions
MATLAB: A Practical Introduction to Programming and Problem Solving
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageLinear Algebra: A Modern IntroductionAlgebraISBN:9781285463247Author:David PoolePublisher:Cengage LearningGlencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw Hill