C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 3PP: (Numerical) Given a one-dimensional array of integer numbers, write and test a function that...
icon
Related questions
Question

ON MATLAB PLS

Function Name: howManyWords
Input:
1. (cell) 1XN cell array where each cell contains strings
Output:
1. (double) 1XN vector where each element has the number of words per cell
Function Description:
You are given a cell array where each cell contains a string, iterate through the cell and find how many words are in each cell respectively. Return a vector with the number of
words per cell.
Notes:
Iteration may be useful (both for and while loops)
▪ Each word inside the cell array is separated by a space
Examples:
ca = {{ 'Let it go'} {'Let it go'} { 'Can''t hold it back anymore'}}
>> words = howManyWords (ca)
% words = [ 3 3 5]
ca2 = {{'Here I stand'} {'In the light of day'} {'Let the storm rage on'} {'The cold never bothered me anyway'}}
>> words2 = howManyWords (ca2)
% words2 = [3 5 5 6]
ca3 = {{'Yes'} {'These are the lyrics for'} {'Let it go'} {'If you did not catch it'} {'Maybe'} {'you should watch'} {'the movie again'
>> words3 = howManyWords (ca3)
%words3 = [ 1 5 3 6 1 3 3]
Transcribed Image Text:Function Name: howManyWords Input: 1. (cell) 1XN cell array where each cell contains strings Output: 1. (double) 1XN vector where each element has the number of words per cell Function Description: You are given a cell array where each cell contains a string, iterate through the cell and find how many words are in each cell respectively. Return a vector with the number of words per cell. Notes: Iteration may be useful (both for and while loops) ▪ Each word inside the cell array is separated by a space Examples: ca = {{ 'Let it go'} {'Let it go'} { 'Can''t hold it back anymore'}} >> words = howManyWords (ca) % words = [ 3 3 5] ca2 = {{'Here I stand'} {'In the light of day'} {'Let the storm rage on'} {'The cold never bothered me anyway'}} >> words2 = howManyWords (ca2) % words2 = [3 5 5 6] ca3 = {{'Yes'} {'These are the lyrics for'} {'Let it go'} {'If you did not catch it'} {'Maybe'} {'you should watch'} {'the movie again' >> words3 = howManyWords (ca3) %words3 = [ 1 5 3 6 1 3 3]
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr