{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-04-06T14:01:22.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-04-06T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":43672,"title":"String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\r\n\r\nTo begin with, let's assume that there are no missing type values in the input string array. \r\n\r\nExample: \r\n\r\n  Input:\r\n  \u003e\u003e x = string({'I','love','MATLAB'})\r\n  x = \r\n    1×3 string array\r\n      \"I\"    \"love\"    \"MATLAB\";\r\n\r\n  Output:\r\n  \u003e\u003e y = {'I','love','MATLAB'}\r\n  y =\r\n    1×3 cell array\r\n      'I'    'love'    'MATLAB';\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eTo begin with, let's assume that there are no missing type values in the input string array.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = string({'I','love','MATLAB'})\r\nx = \r\n  1×3 string array\r\n    \"I\"    \"love\"    \"MATLAB\";\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = {'I','love','MATLAB'}\r\ny =\r\n  1×3 cell array\r\n    'I'    'love'    'MATLAB';\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = str2cell(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = string({'I','love','MATLAB'});\r\ny_correct = {'I','love','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string({'I','love','MATLAB';'I','love','Cody'});\r\ny_correct = {'I','love','MATLAB'\r\n             'I','love','Cody'};\r\nassert(isequal(str2cell(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":153,"test_suite_updated_at":"2016-11-23T06:40:34.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T01:00:23.000Z","updated_at":"2026-03-10T19:51:47.000Z","published_at":"2016-11-22T21:10:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo begin with, let's assume that there are no missing type values in the input string array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = string({'I','love','MATLAB'})\\nx = \\n  1×3 string array\\n    \\\"I\\\"    \\\"love\\\"    \\\"MATLAB\\\";\\n\\nOutput:\\n\u003e\u003e y = {'I','love','MATLAB'}\\ny =\\n  1×3 cell array\\n    'I'    'love'    'MATLAB';]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43663,"title":"Combine the first and last names","description":"MATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array. \r\n\r\nFor example, if the inputs are\r\n\r\n  firstnames = [\"Donald\"; \"Hillary\"];\r\n  lastnames = [\"Trump\"; \"Clinton\"];\r\n\r\nthe output should be:\r\n\r\n  names = [\"Donald Trump\"; \"Hillary Clinton\"];\r\n\r\n","description_html":"\u003cp\u003eMATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array.\u003c/p\u003e\u003cp\u003eFor example, if the inputs are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003efirstnames = [\"Donald\"; \"Hillary\"];\r\nlastnames = [\"Trump\"; \"Clinton\"];\r\n\u003c/pre\u003e\u003cp\u003ethe output should be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003enames = [\"Donald Trump\"; \"Hillary Clinton\"];\r\n\u003c/pre\u003e","function_template":"function y = fullname(firstnames,lastnames)\r\n  y = [firstnames,lastnames];\r\nend","test_suite":"%%\r\nassessFunctionAbsence('regexp','FileName','fullname.m')\r\n\r\n%%\r\nfirstnames = string({'Donald';'Hillary'});\r\nlastnames = string({'Trump';'Clinton'});\r\ny_correct = string({'Donald Trump';'Hillary Clinton'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Bill','Hillary'});\r\nlastnames = string('Clinton');\r\ny_correct = string({'Bill Clinton','Hillary Clinton'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Donald';'Barron';'Eric'});\r\nlastnames = string('Trump');\r\ny_correct = string({'Donald Trump';'Barron Trump';'Eric Trump'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string('Mike');\r\nlastnames = string({'Tyson','Pence','Trout'});\r\ny_correct = string({'Mike Tyson','Mike Pence','Mike Trout'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Donald','Hillary';'Mike','James'});\r\nlastnames = string({'Trump','Clinton';'Pence','Bond'});\r\ny_correct = string({'Donald Trump','Hillary Clinton';'Mike Pence','James Bond'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":170,"test_suite_updated_at":"2017-09-18T00:54:07.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-18T09:31:11.000Z","updated_at":"2026-03-10T21:21:28.000Z","published_at":"2016-11-18T09:31:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if the inputs are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[firstnames = [\\\"Donald\\\"; \\\"Hillary\\\"];\\nlastnames = [\\\"Trump\\\"; \\\"Clinton\\\"];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[names = [\\\"Donald Trump\\\"; \\\"Hillary Clinton\\\"];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43673,"title":"String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\r\n\r\nThe \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values  Part 2\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted *\u003c missing \u003e*, need to be converted to the missing values for cell arrays, denoted *{''}* (i.e., cell of empty character). \r\n\r\nRefer to the R2016b documentation for more information on the \u003chttp://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing missing values for different data types\u003e.\r\n \r\nExample: \r\n\r\n  Input:\r\n  \u003e\u003e x = string({'I','love'}); x(4) = 'MATLAB'\r\n  x = \r\n    1×4 string array\r\n      \"I\"    \"love\"    \u003cmissing\u003e    \"MATLAB\"\r\n  \r\n  Output:\r\n  \u003e\u003e y = {'I', 'love', '', 'MATLAB'}\r\n  y =\r\n    1×3 cell array\r\n      'I'    'love'    ''    'MATLAB'\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eThe \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003ePart 2\u003c/a\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted \u003cb\u003e\u0026lt; missing \u0026gt;\u003c/b\u003e, need to be converted to the missing values for cell arrays, denoted \u003cb\u003e{''}\u003c/b\u003e (i.e., cell of empty character).\u003c/p\u003e\u003cp\u003eRefer to the R2016b documentation for more information on the \u003ca href = \"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\"\u003emissing values for different data types\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = string({'I','love'}); x(4) = 'MATLAB'\r\nx = \r\n  1×4 string array\r\n    \"I\"    \"love\"    \u0026lt;missing\u0026gt;    \"MATLAB\"\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = {'I', 'love', '', 'MATLAB'}\r\ny =\r\n  1×3 cell array\r\n    'I'    'love'    ''    'MATLAB'\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = str2cell(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = string({'I','love','MATLAB'});\r\ny_correct = {'I','love','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string({'I','love'}); x(5) = 'MATLAB';\r\ny_correct = {'I','love','','','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string([1 NaN 2]);\r\ny_correct = {'1','','2'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = strings(3);\r\nx(1) = 'first'; \r\nx(end) = 'last';\r\ny_correct = {'first',  '',     ''\r\n             '',       '',     ''\r\n             '',       '',     'last'};\r\nassert(isequal(str2cell(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":"2016-11-23T06:24:32.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T03:52:19.000Z","updated_at":"2026-03-10T20:16:49.000Z","published_at":"2016-11-22T21:16:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePart 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026lt; missing \u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, need to be converted to the missing values for cell arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{''}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (i.e., cell of empty character).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRefer to the R2016b documentation for more information on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emissing values for different data types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = string({'I','love'}); x(4) = 'MATLAB'\\nx = \\n  1×4 string array\\n    \\\"I\\\"    \\\"love\\\"    \u003cmissing\u003e    \\\"MATLAB\\\"\\n\\nOutput:\\n\u003e\u003e y = {'I', 'love', '', 'MATLAB'}\\ny =\\n  1×3 cell array\\n    'I'    'love'    ''    'MATLAB']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43677,"title":"String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data. \r\n\r\nTo begin with, let's assume that there are no missing type values in the input cell array. \r\n\r\n\r\nExample: \r\n \r\n\r\n  Input:\r\n  \u003e\u003e x = {'I','Love','MATLAB'}\r\n  x =\r\n    1×3 cell array\r\n      'I'    'Love'    'MATLAB'\r\n\r\n  Output:\r\n  \u003e\u003e y = strings(size(x));\r\n  \u003e\u003e [y{:}] = x{:}\r\n  y = \r\n    1×3 string array\r\n      \"I\"    \"Love\"    \"MATLAB\"\r\n\r\nNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score. \r\n\r\nRelated Problems in this series:\r\n\r\n* String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e\r\n","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eTo begin with, let's assume that there are no missing type values in the input cell array.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = {'I','Love','MATLAB'}\r\nx =\r\n  1×3 cell array\r\n    'I'    'Love'    'MATLAB'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = strings(size(x));\r\n\u0026gt;\u0026gt; [y{:}] = x{:}\r\ny = \r\n  1×3 string array\r\n    \"I\"    \"Love\"    \"MATLAB\"\r\n\u003c/pre\u003e\u003cp\u003eNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score.\u003c/p\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = cell2str(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = {'I','love','MATLAB'};\r\ny_correct = strings(size(x));\r\n[y_correct{:}] = x{:};\r\nassert(isequal(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I',   'love',  'MATLAB'\r\n     'I',   'love',  'Cody'};\r\ny_correct = strings(size(x));\r\n[y_correct{:}] = x{:};\r\nassert(isequal(cell2str(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1972,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-22T21:03:53.000Z","updated_at":"2026-04-07T19:11:48.000Z","published_at":"2016-11-22T21:05:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo begin with, let's assume that there are no missing type values in the input cell array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = {'I','Love','MATLAB'}\\nx =\\n  1×3 cell array\\n    'I'    'Love'    'MATLAB'\\n\\nOutput:\\n\u003e\u003e y = strings(size(x));\\n\u003e\u003e [y{:}] = x{:}\\ny = \\n  1×3 string array\\n    \\\"I\\\"    \\\"Love\\\"    \\\"MATLAB\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43674,"title":"String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data. \r\n\r\nThe \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values Part 1\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted *{''}* (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted *\u003c missing \u003e*. \r\n\r\nRefer to the R2016b documentation for more information on the \u003chttp://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing missing values for different data types\u003e. \r\n \r\n\r\nExample: \r\n\r\n  \r\n\r\n  Input:\r\n  \u003e\u003e x = {'I', '', '', 'MATLAB'}\r\n  x =\r\n    1×4 cell array\r\n      'I'    ''    ''    'MATLAB'\r\n\r\n  Output:\r\n  \u003e\u003e y = string('I'); y(4) = 'MATLAB'\r\n  y = \r\n    1×4 string array\r\n      \"I\"    \u003cmissing\u003e    \u003cmissing\u003e    \"MATLAB\"\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e\r\n","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eThe \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003ePart 1\u003c/a\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted \u003cb\u003e{''}\u003c/b\u003e (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted \u003cb\u003e\u0026lt; missing \u0026gt;\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eRefer to the R2016b documentation for more information on the \u003ca href = \"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\"\u003emissing values for different data types\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = {'I', '', '', 'MATLAB'}\r\nx =\r\n  1×4 cell array\r\n    'I'    ''    ''    'MATLAB'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = string('I'); y(4) = 'MATLAB'\r\ny = \r\n  1×4 string array\r\n    \"I\"    \u0026lt;missing\u0026gt;    \u0026lt;missing\u0026gt;    \"MATLAB\"\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = cell2str(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = {'I','love','MATLAB'};\r\ny_correct = string({'I','love','MATLAB'});\r\nassert(isequal(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I', '', '', 'MATLAB'};\r\ny_correct = string('I'); y_correct(4) = 'MATLAB';\r\nassert(isequaln(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I',   '',      'MATLAB'\r\n     '',    'love',  'MATLAB'\r\n     'I',   'love',  ''      };\r\ny_correct = [string('I'),  string(NaN),     string('MATLAB')\r\n             string(NaN),  string('love'),  string('MATLAB')\r\n             string('I'),  string('love'),  string(NaN)     ];\r\nassert(isequaln(cell2str(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":"2016-11-23T06:30:05.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T04:09:03.000Z","updated_at":"2026-03-10T20:06:28.000Z","published_at":"2016-11-22T21:16:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePart 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{''}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026lt; missing \u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRefer to the R2016b documentation for more information on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emissing values for different data types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = {'I', '', '', 'MATLAB'}\\nx =\\n  1×4 cell array\\n    'I'    ''    ''    'MATLAB'\\n\\nOutput:\\n\u003e\u003e y = string('I'); y(4) = 'MATLAB'\\ny = \\n  1×4 string array\\n    \\\"I\\\"    \u003cmissing\u003e    \u003cmissing\u003e    \\\"MATLAB\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43670,"title":"Words Count: A String Array Approach","description":"Given an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\n), arrange the unique words alphabetically in a \u003chttps://www.mathworks.com/help/matlab/characters-and-strings.html string array\u003e and calculate the histogram count of every unique word.\r\n\r\nAssumptions:\r\n\r\n# Case is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\r\n# Punctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\r\n\r\nFor example, given the input txt as a character vector,\r\n\r\n  txt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\n\r\nthe outputs should be\r\n\r\n  words = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\r\n                  'on';'problems';'trivial'});\r\n  count = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n\r\nHint: The R2016b documentation provides a good \u003chttp://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html example\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\r\n\r\nRelated problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach Words Count: A Cell Array Approach\u003e\r\n* Words Count: A String Array Approach","description_html":"\u003cp\u003eGiven an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\n), arrange the unique words alphabetically in a \u003ca href = \"https://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003estring array\u003c/a\u003e and calculate the histogram count of every unique word.\u003c/p\u003e\u003cp\u003eAssumptions:\u003c/p\u003e\u003col\u003e\u003cli\u003eCase is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\u003c/li\u003e\u003cli\u003ePunctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor example, given the input txt as a character vector,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003etxt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\n\u003c/pre\u003e\u003cp\u003ethe outputs should be\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ewords = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\r\n                'on';'problems';'trivial'});\r\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n\u003c/pre\u003e\u003cp\u003eHint: The R2016b documentation provides a good \u003ca href = \"http://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html\"\u003eexample\u003c/a\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\u003c/p\u003e\u003cp\u003eRelated problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach\"\u003eWords Count: A Cell Array Approach\u003c/a\u003e\u003c/li\u003e\u003cli\u003eWords Count: A String Array Approach\u003c/li\u003e\u003c/ul\u003e","function_template":"function [words,count] = wordscount(txt)\r\n  words = txt;\r\n  count = 1;\r\nend","test_suite":"%%\r\ntxt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\nwords = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';'on';'problems';'trivial'});\r\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))\r\n\r\n%%\r\ntxt = sprintf('\\n\\nI love MATLAB and Cody, but I don''t like trivial matlab problems on cody.\\n\\nUnfortunately, there are too many trivial problems on Cody.');\r\nwords = string({'and';'are';'but';'cody';'don''t';'I';'like';'love';'many';'matlab';'on';'problems';'there';'too';'trivial';'unfortunately'});\r\ncount = [1; 1; 1; 3; 1; 2; 1; 1; 1; 2; 2; 2; 1; 1; 2; 1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))\r\n\r\n%%\r\ntxt = ['What is Cody? ',newline,' Cody is a MATLAB Central game', newline ...\r\n       'that expands your knowledge of MATLAB.',newline,...\r\n       'With Cody, you can:',newline, ...\r\n       'Solve problems related to MATLAB code;',newline, ...\r\n       'Find problems, solutions, and players;  ',newline, ...\r\n       'Use search directives to find content; ',newline, ...\r\n       'Challenge the community by contributing problems;',newline, ...\r\n       ' Comment on any problem or solution;',newline,...\r\n       'Like a problem or a solution; ',newline, ...\r\n       'Earn badges;',newline,newline, ...\r\n       'Play now!'];\r\nwords = string({'a';'and';'any';'badges';'by';'can';'central';'challenge';'code';'cody';'comment';...\r\n                'community';'content';'contributing';'directives';'earn';'expands';'find';'game';...\r\n                'is';'knowledge';'like';'matlab';'now';'of';'on';'or';'play';'players';'problem';...\r\n                'problems';'related';'search';'solution';'solutions';'solve';'that';'the';'to';...\r\n                'use';'what';'with';'you';'your'});\r\ncount = [3;1;1;1;1;1;1;1;1;3;1;1;1;1;1;1;1;2;1;2;1;1;3;1;1;1;2;1;1;2;3;1;1;2;1;1;1;1;2;1;1;1;1;1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))","published":true,"deleted":false,"likes_count":12,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":82,"test_suite_updated_at":"2016-12-02T05:47:45.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-20T06:50:46.000Z","updated_at":"2026-03-09T20:37:06.000Z","published_at":"2016-11-20T09:01:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\\\n), arrange the unique words alphabetically in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and calculate the histogram count of every unique word.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssumptions:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCase is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePunctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, given the input txt as a character vector,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[txt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe outputs should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[words = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\\n                'on';'problems';'trivial'});\\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: The R2016b documentation provides a good\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eexample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eWords Count: A Cell Array Approach\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWords Count: A String Array Approach\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":43672,"title":"String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\r\n\r\nTo begin with, let's assume that there are no missing type values in the input string array. \r\n\r\nExample: \r\n\r\n  Input:\r\n  \u003e\u003e x = string({'I','love','MATLAB'})\r\n  x = \r\n    1×3 string array\r\n      \"I\"    \"love\"    \"MATLAB\";\r\n\r\n  Output:\r\n  \u003e\u003e y = {'I','love','MATLAB'}\r\n  y =\r\n    1×3 cell array\r\n      'I'    'love'    'MATLAB';\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eTo begin with, let's assume that there are no missing type values in the input string array.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = string({'I','love','MATLAB'})\r\nx = \r\n  1×3 string array\r\n    \"I\"    \"love\"    \"MATLAB\";\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = {'I','love','MATLAB'}\r\ny =\r\n  1×3 cell array\r\n    'I'    'love'    'MATLAB';\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = str2cell(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = string({'I','love','MATLAB'});\r\ny_correct = {'I','love','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string({'I','love','MATLAB';'I','love','Cody'});\r\ny_correct = {'I','love','MATLAB'\r\n             'I','love','Cody'};\r\nassert(isequal(str2cell(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":153,"test_suite_updated_at":"2016-11-23T06:40:34.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T01:00:23.000Z","updated_at":"2026-03-10T19:51:47.000Z","published_at":"2016-11-22T21:10:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo begin with, let's assume that there are no missing type values in the input string array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = string({'I','love','MATLAB'})\\nx = \\n  1×3 string array\\n    \\\"I\\\"    \\\"love\\\"    \\\"MATLAB\\\";\\n\\nOutput:\\n\u003e\u003e y = {'I','love','MATLAB'}\\ny =\\n  1×3 cell array\\n    'I'    'love'    'MATLAB';]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43663,"title":"Combine the first and last names","description":"MATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array. \r\n\r\nFor example, if the inputs are\r\n\r\n  firstnames = [\"Donald\"; \"Hillary\"];\r\n  lastnames = [\"Trump\"; \"Clinton\"];\r\n\r\nthe output should be:\r\n\r\n  names = [\"Donald Trump\"; \"Hillary Clinton\"];\r\n\r\n","description_html":"\u003cp\u003eMATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array.\u003c/p\u003e\u003cp\u003eFor example, if the inputs are\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003efirstnames = [\"Donald\"; \"Hillary\"];\r\nlastnames = [\"Trump\"; \"Clinton\"];\r\n\u003c/pre\u003e\u003cp\u003ethe output should be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003enames = [\"Donald Trump\"; \"Hillary Clinton\"];\r\n\u003c/pre\u003e","function_template":"function y = fullname(firstnames,lastnames)\r\n  y = [firstnames,lastnames];\r\nend","test_suite":"%%\r\nassessFunctionAbsence('regexp','FileName','fullname.m')\r\n\r\n%%\r\nfirstnames = string({'Donald';'Hillary'});\r\nlastnames = string({'Trump';'Clinton'});\r\ny_correct = string({'Donald Trump';'Hillary Clinton'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Bill','Hillary'});\r\nlastnames = string('Clinton');\r\ny_correct = string({'Bill Clinton','Hillary Clinton'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Donald';'Barron';'Eric'});\r\nlastnames = string('Trump');\r\ny_correct = string({'Donald Trump';'Barron Trump';'Eric Trump'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string('Mike');\r\nlastnames = string({'Tyson','Pence','Trout'});\r\ny_correct = string({'Mike Tyson','Mike Pence','Mike Trout'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))\r\n\r\n%%\r\nfirstnames = string({'Donald','Hillary';'Mike','James'});\r\nlastnames = string({'Trump','Clinton';'Pence','Bond'});\r\ny_correct = string({'Donald Trump','Hillary Clinton';'Mike Pence','James Bond'});\r\nassert(isequal(fullname(firstnames,lastnames),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":170,"test_suite_updated_at":"2017-09-18T00:54:07.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-18T09:31:11.000Z","updated_at":"2026-03-10T21:21:28.000Z","published_at":"2016-11-18T09:31:11.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMATLAB R2016 provides a rich set of functions to work with string arrays. In this problem, you will be given two string arrays of the first names and last names. Your job is to join the first names with the corresponding last names, and output a new string array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, if the inputs are\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[firstnames = [\\\"Donald\\\"; \\\"Hillary\\\"];\\nlastnames = [\\\"Trump\\\"; \\\"Clinton\\\"];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[names = [\\\"Donald Trump\\\"; \\\"Hillary Clinton\\\"];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43673,"title":"String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\r\n\r\nThe \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values  Part 2\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted *\u003c missing \u003e*, need to be converted to the missing values for cell arrays, denoted *{''}* (i.e., cell of empty character). \r\n\r\nRefer to the R2016b documentation for more information on the \u003chttp://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing missing values for different data types\u003e.\r\n \r\nExample: \r\n\r\n  Input:\r\n  \u003e\u003e x = string({'I','love'}); x(4) = 'MATLAB'\r\n  x = \r\n    1×4 string array\r\n      \"I\"    \"love\"    \u003cmissing\u003e    \"MATLAB\"\r\n  \r\n  Output:\r\n  \u003e\u003e y = {'I', 'love', '', 'MATLAB'}\r\n  y =\r\n    1×3 cell array\r\n      'I'    'love'    ''    'MATLAB'\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eThe \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003ePart 2\u003c/a\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted \u003cb\u003e\u0026lt; missing \u0026gt;\u003c/b\u003e, need to be converted to the missing values for cell arrays, denoted \u003cb\u003e{''}\u003c/b\u003e (i.e., cell of empty character).\u003c/p\u003e\u003cp\u003eRefer to the R2016b documentation for more information on the \u003ca href = \"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\"\u003emissing values for different data types\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = string({'I','love'}); x(4) = 'MATLAB'\r\nx = \r\n  1×4 string array\r\n    \"I\"    \"love\"    \u0026lt;missing\u0026gt;    \"MATLAB\"\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = {'I', 'love', '', 'MATLAB'}\r\ny =\r\n  1×3 cell array\r\n    'I'    'love'    ''    'MATLAB'\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = str2cell(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = string({'I','love','MATLAB'});\r\ny_correct = {'I','love','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string({'I','love'}); x(5) = 'MATLAB';\r\ny_correct = {'I','love','','','MATLAB'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = string([1 NaN 2]);\r\ny_correct = {'1','','2'};\r\nassert(isequal(str2cell(x),y_correct))\r\n\r\n%%\r\nx = strings(3);\r\nx(1) = 'first'; \r\nx(end) = 'last';\r\ny_correct = {'first',  '',     ''\r\n             '',       '',     ''\r\n             '',       '',     'last'};\r\nassert(isequal(str2cell(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":"2016-11-23T06:24:32.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T03:52:19.000Z","updated_at":"2026-03-10T20:16:49.000Z","published_at":"2016-11-22T21:16:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a string array of text data. Your job is to convert the string array to a cell array of character vectors, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePart 2\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e assuming no missing values in the input string array is a good starting point. In this problem, the missing values for string arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026lt; missing \u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, need to be converted to the missing values for cell arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{''}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (i.e., cell of empty character).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRefer to the R2016b documentation for more information on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emissing values for different data types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = string({'I','love'}); x(4) = 'MATLAB'\\nx = \\n  1×4 string array\\n    \\\"I\\\"    \\\"love\\\"    \u003cmissing\u003e    \\\"MATLAB\\\"\\n\\nOutput:\\n\u003e\u003e y = {'I', 'love', '', 'MATLAB'}\\ny =\\n  1×3 cell array\\n    'I'    'love'    ''    'MATLAB']]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43677,"title":"String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data. \r\n\r\nTo begin with, let's assume that there are no missing type values in the input cell array. \r\n\r\n\r\nExample: \r\n \r\n\r\n  Input:\r\n  \u003e\u003e x = {'I','Love','MATLAB'}\r\n  x =\r\n    1×3 cell array\r\n      'I'    'Love'    'MATLAB'\r\n\r\n  Output:\r\n  \u003e\u003e y = strings(size(x));\r\n  \u003e\u003e [y{:}] = x{:}\r\n  y = \r\n    1×3 string array\r\n      \"I\"    \"Love\"    \"MATLAB\"\r\n\r\nNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score. \r\n\r\nRelated Problems in this series:\r\n\r\n* String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values   String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003e\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e\r\n","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eTo begin with, let's assume that there are no missing type values in the input cell array.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = {'I','Love','MATLAB'}\r\nx =\r\n  1×3 cell array\r\n    'I'    'Love'    'MATLAB'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = strings(size(x));\r\n\u0026gt;\u0026gt; [y{:}] = x{:}\r\ny = \r\n  1×3 string array\r\n    \"I\"    \"Love\"    \"MATLAB\"\r\n\u003c/pre\u003e\u003cp\u003eNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score.\u003c/p\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\"\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = cell2str(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = {'I','love','MATLAB'};\r\ny_correct = strings(size(x));\r\n[y_correct{:}] = x{:};\r\nassert(isequal(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I',   'love',  'MATLAB'\r\n     'I',   'love',  'Cody'};\r\ny_correct = strings(size(x));\r\n[y_correct{:}] = x{:};\r\nassert(isequal(cell2str(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":7,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1972,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-22T21:03:53.000Z","updated_at":"2026-04-07T19:11:48.000Z","published_at":"2016-11-22T21:05:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo begin with, let's assume that there are no missing type values in the input cell array.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = {'I','Love','MATLAB'}\\nx =\\n  1×3 cell array\\n    'I'    'Love'    'MATLAB'\\n\\nOutput:\\n\u003e\u003e y = strings(size(x));\\n\u003e\u003e [y{:}] = x{:}\\ny = \\n  1×3 string array\\n    \\\"I\\\"    \\\"Love\\\"    \\\"MATLAB\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote that the example shown above is not the best way to solve this problem. Try other approaches in order to achieve a leading score.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43674-string-array-basics-part-3-convert-cell-array-to-string-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43674,"title":"String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array","description":"\u003chttp://www.mathworks.com/help/matlab/characters-and-strings.html String array\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data. \r\n\r\nThe \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values Part 1\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted *{''}* (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted *\u003c missing \u003e*. \r\n\r\nRefer to the R2016b documentation for more information on the \u003chttp://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing missing values for different data types\u003e. \r\n \r\n\r\nExample: \r\n\r\n  \r\n\r\n  Input:\r\n  \u003e\u003e x = {'I', '', '', 'MATLAB'}\r\n  x =\r\n    1×4 cell array\r\n      'I'    ''    ''    'MATLAB'\r\n\r\n  Output:\r\n  \u003e\u003e y = string('I'); y(4) = 'MATLAB'\r\n  y = \r\n    1×4 string array\r\n      \"I\"    \u003cmissing\u003e    \u003cmissing\u003e    \"MATLAB\"\r\n\r\nRelated Problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values   String Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003e \r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values   String Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003e \r\n* String Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values   String Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003e\r\n","description_html":"\u003cp\u003e\u003ca href = \"http://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003eString array\u003c/a\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/p\u003e\u003cp\u003eThe \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003ePart 1\u003c/a\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted \u003cb\u003e{''}\u003c/b\u003e (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted \u003cb\u003e\u0026lt; missing \u0026gt;\u003c/b\u003e.\u003c/p\u003e\u003cp\u003eRefer to the R2016b documentation for more information on the \u003ca href = \"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\"\u003emissing values for different data types\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\n\u0026gt;\u0026gt; x = {'I', '', '', 'MATLAB'}\r\nx =\r\n  1×4 cell array\r\n    'I'    ''    ''    'MATLAB'\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\n\u0026gt;\u0026gt; y = string('I'); y(4) = 'MATLAB'\r\ny = \r\n  1×4 string array\r\n    \"I\"    \u0026lt;missing\u0026gt;    \u0026lt;missing\u0026gt;    \"MATLAB\"\r\n\u003c/pre\u003e\u003cp\u003eRelated Problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\"\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\"\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/a\u003e\u003c/li\u003e\u003cli\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/li\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\"\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/a\u003e\u003c/li\u003e\u003c/ul\u003e","function_template":"function y = cell2str(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = {'I','love','MATLAB'};\r\ny_correct = string({'I','love','MATLAB'});\r\nassert(isequal(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I', '', '', 'MATLAB'};\r\ny_correct = string('I'); y_correct(4) = 'MATLAB';\r\nassert(isequaln(cell2str(x),y_correct))\r\n\r\n%%\r\nx = {'I',   '',      'MATLAB'\r\n     '',    'love',  'MATLAB'\r\n     'I',   'love',  ''      };\r\ny_correct = [string('I'),  string(NaN),     string('MATLAB')\r\n             string(NaN),  string('love'),  string('MATLAB')\r\n             string('I'),  string('love'),  string(NaN)     ];\r\nassert(isequaln(cell2str(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":"2016-11-23T06:30:05.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-21T04:09:03.000Z","updated_at":"2026-03-10T20:06:28.000Z","published_at":"2016-11-22T21:16:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and cell array are two types of containers for storing pieces of data. In this problem, you will be given a cell array of character vectors. Your job is to convert the cell array to a string array, which stores the same pieces of text data.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ePart 1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e assuming no missing values in the input cell array is a good starting point. In this problem, the missing values for cell array of character vectors, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e{''}\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (i.e., cell of empty character), need to be converted to the missing values for string arrays, denoted\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e\u0026lt; missing \u0026gt;\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRefer to the R2016b documentation for more information on the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/ismissing.html?=ismissing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emissing values for different data types\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[Input:\\n\u003e\u003e x = {'I', '', '', 'MATLAB'}\\nx =\\n  1×4 cell array\\n    'I'    ''    ''    'MATLAB'\\n\\nOutput:\\n\u003e\u003e y = string('I'); y(4) = 'MATLAB'\\ny = \\n  1×4 string array\\n    \\\"I\\\"    \u003cmissing\u003e    \u003cmissing\u003e    \\\"MATLAB\\\"]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated Problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43677-string-array-basics-part-1-convert-cell-array-to-string-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 1: Convert Cell Array to String Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43672-string-array-basics-part-2-convert-string-array-to-cell-array-no-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 2: Convert String Array to Cell Array; No Missing Values\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 3: Convert Cell Array with Missing Values to String Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43673-string-array-basics-part-4-convert-string-array-to-cell-array-with-missing-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eString Array Basics, Part 4: Convert String Array with Missing Values to Cell Array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":43670,"title":"Words Count: A String Array Approach","description":"Given an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\n), arrange the unique words alphabetically in a \u003chttps://www.mathworks.com/help/matlab/characters-and-strings.html string array\u003e and calculate the histogram count of every unique word.\r\n\r\nAssumptions:\r\n\r\n# Case is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\r\n# Punctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\r\n\r\nFor example, given the input txt as a character vector,\r\n\r\n  txt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\n\r\nthe outputs should be\r\n\r\n  words = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\r\n                  'on';'problems';'trivial'});\r\n  count = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n\r\nHint: The R2016b documentation provides a good \u003chttp://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html example\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\r\n\r\nRelated problems in this series:\r\n\r\n* \u003chttp://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach Words Count: A Cell Array Approach\u003e\r\n* Words Count: A String Array Approach","description_html":"\u003cp\u003eGiven an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\n), arrange the unique words alphabetically in a \u003ca href = \"https://www.mathworks.com/help/matlab/characters-and-strings.html\"\u003estring array\u003c/a\u003e and calculate the histogram count of every unique word.\u003c/p\u003e\u003cp\u003eAssumptions:\u003c/p\u003e\u003col\u003e\u003cli\u003eCase is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\u003c/li\u003e\u003cli\u003ePunctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor example, given the input txt as a character vector,\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003etxt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\n\u003c/pre\u003e\u003cp\u003ethe outputs should be\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ewords = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\r\n                'on';'problems';'trivial'});\r\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n\u003c/pre\u003e\u003cp\u003eHint: The R2016b documentation provides a good \u003ca href = \"http://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html\"\u003eexample\u003c/a\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\u003c/p\u003e\u003cp\u003eRelated problems in this series:\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach\"\u003eWords Count: A Cell Array Approach\u003c/a\u003e\u003c/li\u003e\u003cli\u003eWords Count: A String Array Approach\u003c/li\u003e\u003c/ul\u003e","function_template":"function [words,count] = wordscount(txt)\r\n  words = txt;\r\n  count = 1;\r\nend","test_suite":"%%\r\ntxt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';\r\nwords = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';'on';'problems';'trivial'});\r\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))\r\n\r\n%%\r\ntxt = sprintf('\\n\\nI love MATLAB and Cody, but I don''t like trivial matlab problems on cody.\\n\\nUnfortunately, there are too many trivial problems on Cody.');\r\nwords = string({'and';'are';'but';'cody';'don''t';'I';'like';'love';'many';'matlab';'on';'problems';'there';'too';'trivial';'unfortunately'});\r\ncount = [1; 1; 1; 3; 1; 2; 1; 1; 1; 2; 2; 2; 1; 1; 2; 1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))\r\n\r\n%%\r\ntxt = ['What is Cody? ',newline,' Cody is a MATLAB Central game', newline ...\r\n       'that expands your knowledge of MATLAB.',newline,...\r\n       'With Cody, you can:',newline, ...\r\n       'Solve problems related to MATLAB code;',newline, ...\r\n       'Find problems, solutions, and players;  ',newline, ...\r\n       'Use search directives to find content; ',newline, ...\r\n       'Challenge the community by contributing problems;',newline, ...\r\n       ' Comment on any problem or solution;',newline,...\r\n       'Like a problem or a solution; ',newline, ...\r\n       'Earn badges;',newline,newline, ...\r\n       'Play now!'];\r\nwords = string({'a';'and';'any';'badges';'by';'can';'central';'challenge';'code';'cody';'comment';...\r\n                'community';'content';'contributing';'directives';'earn';'expands';'find';'game';...\r\n                'is';'knowledge';'like';'matlab';'now';'of';'on';'or';'play';'players';'problem';...\r\n                'problems';'related';'search';'solution';'solutions';'solve';'that';'the';'to';...\r\n                'use';'what';'with';'you';'your'});\r\ncount = [3;1;1;1;1;1;1;1;1;3;1;1;1;1;1;1;1;2;1;2;1;1;3;1;1;1;2;1;1;2;3;1;1;2;1;1;1;1;2;1;1;1;1;1];\r\n[words1,count1] = wordscount(txt);\r\nassert(isequal(lower(words1),lower(words))\u0026isequal(count,count1))","published":true,"deleted":false,"likes_count":12,"comments_count":2,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":82,"test_suite_updated_at":"2016-12-02T05:47:45.000Z","rescore_all_solutions":false,"group_id":16,"created_at":"2016-11-20T06:50:46.000Z","updated_at":"2026-03-09T20:37:06.000Z","published_at":"2016-11-20T09:01:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an input character vector consisting of words, punctuation marks, white spaces, and possibly newline characters (\\\\n), arrange the unique words alphabetically in a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"https://www.mathworks.com/help/matlab/characters-and-strings.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003estring array\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and calculate the histogram count of every unique word.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAssumptions:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCase is insensitive, e.g., WORDS and words are treated as the same word, and you may return in the output string array either the uppercase or lowercase.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePunctuation marks are limited only to comma (,), period (.), colon (:), semi-colon (;), question mark (?), and exclamation mark (!).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example, given the input txt as a character vector,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[txt = 'I love MATLAB and Cody, but I don''t like trivial matlab problems on cody.';]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe outputs should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[words = string({'and';'but';'Cody';'don''t';'I';'like';'love';'MATLAB';...\\n                'on';'problems';'trivial'});\\ncount = [1; 1; 2; 1; 2; 1; 1; 2; 1; 1; 1];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHint: The R2016b documentation provides a good\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/matlab_prog/analyze-text-data-with-string-arrays.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eexample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of text data analysis via the string array approach. However, some steps illustrated in that example are unnecessary, and we can indeed accomplish the same task in a simpler way.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRelated problems in this series:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/43671-words-count-a-cell-array-approach\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eWords Count: A Cell Array Approach\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWords Count: A String Array Approach\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"string array\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"string array\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"string array\"","","\"","string array","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f636e365140\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f636e3650a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f636e3647e0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f636e3653c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f636e365320\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f636e365280\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f636e3651e0\u003e":"tag:\"string array\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f636e3651e0\u003e":"tag:\"string array\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"cody-search","password":"78X075ddcV44","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"string array\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"string array\"","","\"","string array","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f636e365140\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f636e3650a0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f636e3647e0\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f636e3653c0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f636e365320\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f636e365280\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f636e3651e0\u003e":"tag:\"string array\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f636e3651e0\u003e":"tag:\"string array\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":43672,"difficulty_rating":"easy"},{"id":43663,"difficulty_rating":"easy-medium"},{"id":43673,"difficulty_rating":"easy-medium"},{"id":43677,"difficulty_rating":"easy-medium"},{"id":43674,"difficulty_rating":"easy-medium"},{"id":43670,"difficulty_rating":"medium"}]}}