05 Jun Your file must begin with the function definition
Question
Lab Practical 21
Due: EOC (End of Class)
Goal
In this lab, we will use strfind() to take a single line of text and break it up into a user defined number of
words per line.
Setup
Create a new function file called textwrap.m.
Your file must begin with the function definition line, Help Line, and the specified information:
%{
Name
ITP 168, Spring 2016
Lab 21
USC email
Revision History
%}
Requirements
This function takes in two parameters. The first input parameter is a string variable of only one row. If
there are multiple rows, throw an error. The second parameter is the number of words per row, it
should be a scalar integer value greater than 1.
Your function should perform the following:
1. Determine the number of words in the string
2. Using the user’s input for the number of words per line, calculate the number of lines
3. Create rows of words (from the original string) in a string array by concatenating vertically
a. Start by creating just the first line.
b. Create a loop that loops from the second line, until the second-to-last line
i. Determine the next line of text using the words-per-line and the original string
ii. Vertically concatenate the previous lines with this new line
c. Once the loop is over, add on the last line of the text (it may or may not have the same
number of words as the previous lines)
4. Give the vertically concatenated string array as the output
Sample output
Below is the sample output.
Page 1 of 2
>> str = ‘It was the best of times, it was the worst of times, it was the age
of wisdom, it was the age of foolishness, it was the epoch of belief, it was
the epoch of incredulity, it was the season of Light, it was the season of
Darkness, it was the spring of hope, it was the winter of despair, we had
everything before us, we had nothing before us, we were all going direct to
Heaven, we were all going direct the other way–in short, the period was so
far like the present period, that some of its noisiest authorities insisted
on its being received, for good or for evil, in the superlative degree of
comparison only.’
>> newText = textwrap(str,8)
newText =
It was the best of times, it was
the worst of times, it was the age
of wisdom, it was the age of foolishness,
it was the epoch of belief, it was
the epoch of incredulity, it was the season
of Light, it was the season of Darkness,
it was the spring of hope, it was
the winter of despair, we had everything before
us, we had nothing before us, we were
all going direct to Heaven, we were all
going direct the other way–in short, the period
was so far like the present period, that
some of its noisiest authorities insisted on its
being received, for good or for evil, in
the superlative degree of comparison only.
Deliverables
1. A compressed Lab21.zip file containing the file named textwrap.m. It must be submitted
through Blackboard.
Page 2 of 2
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.
