Question
sample cell array: A = {[1 2 3], true, 'hi there', 42, false, 'abc'} Write a function, using matlab, named cellParse that has one parameter,
sample cell array: A = {[1 2 3], true, 'hi there', 42, false, 'abc'}
Write a function, using matlab, named cellParse that has one parameter, a cell array. Each element of the cell array is either a string, a vector of numbers, or a boolean value. The function will return 6 values as follows:
nStr: the number of strings in the cell array
nVec: the number of vectors
nBool: the number of Boolean values
cString: a cell array of all the strings in alphabetic order
vecLength: the average length of all the vectors
allTrue: true if all the Boolean values are true, false otherwise
Suggested approach do incremental development.
Step 1: set up the function so that it loops over the cell array and returns one value, nStr
Step 2: add to your loop and your output argument so that the function also returns nVec
Step 3: add to your loop and your output argument so that the function also returns nBool
Step 4: You are already counting the number of numeric vectors. Add code that computes the sum of the lengths of all the numeric vectors, and code to compute the average length.
Step 5: You are already counting the number of Boolean elements. Add code that will determine whether all values are true or not.
Step 6: You are already counting the character strings. Add code that will put each character string into a cell array.
Step 7: Add code to sort the cell array of strings
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started