To create:
The length of the character
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
- MATLAB: An Introduction with ApplicationsStatisticsISBN:9781119256830Author:Amos GilatPublisher:John Wiley & Sons IncProbability and Statistics for Engineering and th...StatisticsISBN:9781305251809Author:Jay L. DevorePublisher:Cengage LearningStatistics for The Behavioral Sciences (MindTap C...StatisticsISBN:9781305504912Author:Frederick J Gravetter, Larry B. WallnauPublisher:Cengage Learning
- Elementary Statistics: Picturing the World (7th E...StatisticsISBN:9780134683416Author:Ron Larson, Betsy FarberPublisher:PEARSONThe Basic Practice of StatisticsStatisticsISBN:9781319042578Author:David S. Moore, William I. Notz, Michael A. FlignerPublisher:W. H. FreemanIntroduction to the Practice of StatisticsStatisticsISBN:9781319013387Author:David S. Moore, George P. McCabe, Bruce A. CraigPublisher:W. H. Freeman