Objective Using Cell Arrays in MATLAB Questions 1 Suppose yo

Objective: Using Cell Arrays in MATLAB

Questions:

1) Suppose you have the following string:

str1 = \'A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. Cell arrays commonly contain either lists of text strings, combinations of text and numbers, or numeric arrays of different sizes. Refer to sets of cells by enclosing indices in smooth parentheses. Access the contents of cells by indexing with curly braces.\';

a) Make a cell array called cellString. Fill cellString with the individual words from str1, so that each element of cellString is a word from str1. The words should be lowercase and stripped of any punctuation or commas.

b) Show the two different ways ({}, ()), to index the 6th element of cellString. Explain with a brief comment what is returned by each technique, and why they are different.

Solution

Code:

str1 = \'A cell array is a data type with indexed data containers called cells, where each cell can contain any type of data. Cell arrays commonly contain either lists of text strings, combinations of text and numbers, or numeric arrays of different sizes. Refer to sets of cells by enclosing indices in smooth parentheses. Access the contents of cells by indexing with curly braces.\';
str2 = regexprep(str1,\'[^\\w\'\']\',\' \');%removing punctuations
str3 = strsplit(lower(str2),\' \');%splitting the string into array
c = cell(str3);
c(6) %Use parentheses () for indexing into a cell array to collect a subset of cells together in another cell array.
c{6} %Use curly braces {} for setting or getting the contents of cell arrays.

Output:

ans =

\'data\'


ans =

data

Objective: Using Cell Arrays in MATLAB Questions: 1) Suppose you have the following string: str1 = \'A cell array is a data type with indexed data containers ca

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site