To create:
The length of the string and also its first and last characters.
Answer to Problem 7.1P
Solution:
The script is saved and executed as follows.
Explanation of Solution
Consider the string is Akhil.
The length of the string is 5.
The first character of the string is A.
The last character of the string is l.
MATLAB Code:
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_45251_7_1P.m in the current folder. Execute the program by typing the string name at the command window to create the length of the character
Result:
Therefore, the script is saved and executed.
Want to see more full solutions like this?
Chapter 7 Solutions
Matlab, Fourth Edition: A Practical Introduction to Programming and Problem Solving
- Algebra: Structure And Method, Book 1AlgebraISBN:9780395977224Author:Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. ColePublisher:McDougal LittellAlgebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:CengageCollege Algebra (MindTap Course List)AlgebraISBN:9781305652231Author:R. David Gustafson, Jeff HughesPublisher:Cengage Learning
- Calculus For The Life SciencesCalculusISBN:9780321964038Author:GREENWELL, Raymond N., RITCHEY, Nathan P., Lial, Margaret L.Publisher:Pearson Addison Wesley,Glencoe Algebra 1, Student Edition, 9780079039897...AlgebraISBN:9780079039897Author:CarterPublisher:McGraw HillMathematics For Machine TechnologyAdvanced MathISBN:9781337798310Author:Peterson, John.Publisher:Cengage Learning,