{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.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":"2025-12-14T00: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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35:49.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\u003eCreate the matrix:\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[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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: Use\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":1723,"title":"Square wave average calculation","description":"Given its peak and duty cycle, calculate avg value of square wave","description_html":"\u003cp\u003eGiven its peak and duty cycle, calculate avg value of square wave\u003c/p\u003e","function_template":"function avg = your_fcn_name(peak,duty)\r\n  y = x;\r\nend","test_suite":"%%\r\npeak = 5;\r\nduty = 0.6\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(peak,duty),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":14448,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":131,"test_suite_updated_at":"2013-07-18T07:04:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-18T07:01:55.000Z","updated_at":"2026-03-09T20:58:01.000Z","published_at":"2013-07-18T07:04: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 its peak and duty cycle, calculate avg value of square wave\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":42732,"title":"Average Grade","description":"Given a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.","description_html":"\u003cp\u003eGiven a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.\u003c/p\u003e","function_template":"function y = ave_grade(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [65 77 83 92 86];\r\ny_correct = 80.6;\r\nassert(isequal(ave_grade(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":62985,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":182,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-02-18T16:16:41.000Z","updated_at":"2026-03-31T09:52:16.000Z","published_at":"2016-02-18T16:17: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.\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":42351,"title":"Average valid values of arrays","description":"Given a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\r\n\r\n  x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\n  minValue = -10;\r\n  maxValue = 10;\r\n  y = validAverage(x, minValue, maxValue) = -3.2\r\n\r\nTo keep it simple, let's assume minValue and maxValue are within the array range.","description_html":"\u003cp\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminValue = -10;\r\nmaxValue = 10;\r\ny = validAverage(x, minValue, maxValue) = -3.2\r\n\u003c/pre\u003e\u003cp\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\u003c/p\u003e","function_template":"function y = validAverage(x, minV, maxV)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = 1;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = -3.2;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx=1:100;\r\nminV=20;\r\nmaxV=80;\r\ny_correct = 50;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":44306,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":"2015-06-01T21:37:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-01T21:16:24.000Z","updated_at":"2026-02-17T15:29:50.000Z","published_at":"2015-06-01T21:25:20.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 a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue. Example:\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[x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\\nminValue = -10;\\nmaxValue = 10;\\ny = validAverage(x, minValue, maxValue) = -3.2]]\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\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\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":1216,"title":"Mean ignoring NaNs","description":"Define a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).","description_html":"\u003cp\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\u003c/p\u003e","function_template":"function y=average(x,d)\r\ny=0;\r\n","test_suite":"%%\r\nx=[1 5 9;2 6 10;3 nan 11;nan nan nan];\r\ny_correct=[2 5.5 10];\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[5;6;7;nan];\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=x;\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=cat(3,[1 5 9;NaN 6 10;NaN 7 NaN;4 8 12],...\r\n [13 17 21;14 18 22;15 19 NaN;16 20 24]);\r\ny_correct=cat(3,[15 39 62]/6,[87 111 134]/6);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=cat(3,[5;8;7;8],[17;18;17;20]);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[7 11 15;14 12 16;15 13 NaN;10 14 18];\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=zeros(2,1,0);\r\ny_correct=mean(x);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,2);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,3);\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-19T20:54:55.000Z","updated_at":"2026-03-05T14:17:40.000Z","published_at":"2013-01-19T21:44:47.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\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":44852,"title":"Mean number of letters per word (Easy)","description":"Given a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. All characters in the array are either letters or spaces.\r\n\r\n2. There are no redundant spaces.\r\n\r\n3. Except for spaces, there is no punctuation in the sentence.\r\n\r\n4. There will always be at least two words in the sentence.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n\r\nThe next problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard Problem 44853\u003e.","description_html":"\u003cp\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. All characters in the array are either letters or spaces.\u003c/p\u003e\u003cp\u003e2. There are no redundant spaces.\u003c/p\u003e\u003cp\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/p\u003e\u003cp\u003e4. There will always be at least two words in the sentence.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\n\u003c/pre\u003e\u003cp\u003eThe next problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\"\u003eProblem 44853\u003c/a\u003e.\u003c/p\u003e","function_template":"function a = your_fcn_name(c)\r\n    a = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Hello world'),5.000))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('The quick brown fox jumps over the lazy dog'),3.889))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Another one bites the dust'),4.400))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Antidisestablishmentarianism is the longest nonscientific word in the English language'),7.700))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I ate pudding'),3.667))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I hate pudding'),4.000))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T20:34:25.000Z","updated_at":"2026-03-24T12:02:15.000Z","published_at":"2019-02-16T21:25: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:r\u003e\u003cw:t\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\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\u003eYou may make the following assumptions:\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\u003e1. All characters in the array are either letters or spaces.\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\u003e2. There are no redundant spaces.\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\u003e3. Except for spaces, there is no punctuation in the sentence.\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\u003e4. There will always be at least two words in the sentence.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;]]\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[c = 'Another one bites the dust';\\n\\na = 4.400;]]\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 next problem in this series is\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/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44853\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\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":106,"title":"Weighted average","description":"Given two lists of numbers, determine the weighted average as follows\r\nExample\r\n [1 2 3] and [10 15 20]\r\nshould result in\r\n 33.3333  (1*10 + 2*15 + 3*20)/3","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 142.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 71.4333px; transform-origin: 407px 71.4333px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 220.5px 8px; transform-origin: 220.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two lists of numbers, determine the weighted average as follows\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26.5px 8px; transform-origin: 26.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; \"\u003e [1 2 3] and \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 40px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 40px 8.5px; \"\u003e[10 15 20]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eshould result in\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 33.3333  (1*10 + 2*15 + 3*20)/3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = weighted_average(x,w)\r\n  y =\r\nend","test_suite":"%%\r\nx = [1 2 3];\r\nw = [10 15 20];\r\ny_correct = 100/3;\r\nassert(isequal(weighted_average(x,w),y_correct))\r\n\r\n%%\r\nx = [0 -2 3];\r\nw = [10 0 10];\r\ny_correct = 10;\r\nassert(isequal(weighted_average(x,w),y_correct))","published":true,"deleted":false,"likes_count":34,"comments_count":24,"created_by":140,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6714,"test_suite_updated_at":"2014-10-09T20:20:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T01:16:10.000Z","updated_at":"2026-03-16T05:03:07.000Z","published_at":"2012-01-26T01:18:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two lists of numbers, determine the weighted average as follows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\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[ [1 2 3] and [10 15 20]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eshould result in\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[ 33.3333  (1*10 + 2*15 + 3*20)/3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2349,"title":"Elements with highest local average","description":"Input v is a row vector such that length(v)\u003e3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\r\n\r\nExample:\r\n\r\nInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\r\n\r\nOutput: vOut=[7 8 9];\r\n\r\nThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.","description_html":"\u003cp\u003eInput v is a row vector such that length(v)\u0026gt;3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\u003c/p\u003e\u003cp\u003eOutput: vOut=[7 8 9];\u003c/p\u003e\u003cp\u003eThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n\r\n\r\n\r\n\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5 6 7 8 9];\r\ny_correct = [7 8 9];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 2 3];\r\ny_correct = [1 2 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0];\r\ny_correct = [0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [3 3 3 1 1 1 2 3 4];\r\ny_correct = [3 3 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = 1000:-1:1;\r\ny_correct = [1000 999 998];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":98,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":39,"created_at":"2014-06-05T13:41:48.000Z","updated_at":"2026-04-02T08:10:41.000Z","published_at":"2014-06-05T13:43:55.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInput v is a row vector such that length(v)\u0026gt;3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: vOut=[7 8 9];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.\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":44816,"title":"Word Distance - Average Sort","description":"Based on the method of \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44815-word-distance-sum this problem\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if \r\n\r\n str_arr = {'jazz','cab','tree'}\r\n\r\nthen \r\n\r\n d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]\r\n\r\nwhich would result in the following sorted order:\r\n\r\n str_arr_sort = {'cab','tree','jazz'}\r\n\r\nRemember that the method is case insensitive. See the test suite for examples.","description_html":"\u003cp\u003eBased on the method of \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44815-word-distance-sum\"\u003ethis problem\u003c/a\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if\u003c/p\u003e\u003cpre\u003e str_arr = {'jazz','cab','tree'}\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]\u003c/pre\u003e\u003cp\u003ewhich would result in the following sorted order:\u003c/p\u003e\u003cpre\u003e str_arr_sort = {'cab','tree','jazz'}\u003c/pre\u003e\u003cp\u003eRemember that the method is case insensitive. See the test suite for examples.\u003c/p\u003e","function_template":"function d = word_distance_sort(str_arr)\r\n d = 1;\r\nend","test_suite":"%%\r\nassert(isequal(word_distance_sort({'jazz','cab','tree'}),{'cab','tree','jazz'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'first','second','third'}),{'first','second','third'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'the','longest','words','supercede','some','of','the','shortest'}), ...\r\n\t{'some','longest','of','the','the','supercede','shortest','words'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'one','TWO','Three','FouR','fiVe','six','sEvEn','EiGHt','NINe','ten'}), ...\r\n\t{'one','TWO','EiGHt','FouR','NINe','Three','ten','fiVe','six','sEvEn'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'Why','is','it','that','this','does','not','work','as','expected'}), ...\r\n\t{'not','work','is','it','this','does','as','expected','that','Why'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'set','of','very','short','words','for','this','test','case'}), ...\r\n\t{'for','of','short','this','test','words','case','very','set'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'iron','zinc','carbon','molybdenum','praseodymium','silicon'}), ...\r\n\t{'iron','silicon','molybdenum','carbon','zinc','praseodymium'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'crazier','craziest','crazy'}), ...\r\n\t{'crazy','craziest','crazier'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'this','test','case','with','only','four','each','word'}), ...\r\n\t{'each','only','four','this','word','test','case','with'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'largest','smallest','sourest','sweetest'}), ...\r\n\t{'sourest','smallest','largest','sweetest'}))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-01-02T15:43:24.000Z","updated_at":"2025-11-21T14:57:55.000Z","published_at":"2019-01-09T15:06:52.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\u003eBased on the method of\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/matlabcentral/cody/problems/44815-word-distance-sum\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethis problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if\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[ str_arr = {'jazz','cab','tree'}]]\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\u003ethen\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[ d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]]]\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\u003ewhich would result in the following sorted order:\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[ str_arr_sort = {'cab','tree','jazz'}]]\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\u003eRemember that the method is case insensitive. See the test suite for examples.\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":44844,"title":"Moving average ","description":"A moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\r\n\r\nA variable window size, w, whenever possible, i.e.\r\n\r\n  w = 3;\r\n\r\nmeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\r\n\r\n\r\nreturns a ROW vector of moving average values\r\n\r\nThe following inputs: \r\n\r\n  x = [1,2,3,4]; y = [3,5,7,9]; w = 2;\r\n\r\nshould output:\r\n\r\n  ys = [3,5,7,9];\r\n\r\nThe following inputs: \r\n\r\n  x = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;\r\n\r\nshould output:\r\n\r\n  ys = [2,4.5,6.6,8.5,10];\r\n\r\n\r\nNote: the last test case is meant to be a challenge...","description_html":"\u003cp\u003eA moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\u003c/p\u003e\u003cp\u003eA variable window size, w, whenever possible, i.e.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ew = 3;\r\n\u003c/pre\u003e\u003cp\u003emeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\u003c/p\u003e\u003cp\u003ereturns a ROW vector of moving average values\u003c/p\u003e\u003cp\u003eThe following inputs:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [1,2,3,4]; y = [3,5,7,9]; w = 2;\r\n\u003c/pre\u003e\u003cp\u003eshould output:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eys = [3,5,7,9];\r\n\u003c/pre\u003e\u003cp\u003eThe following inputs:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;\r\n\u003c/pre\u003e\u003cp\u003eshould output:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eys = [2,4.5,6.6,8.5,10];\r\n\u003c/pre\u003e\u003cp\u003eNote: the last test case is meant to be a challenge...\u003c/p\u003e","function_template":"function ys = movingAverage(x,y,w)\r\n  ys = y;\r\nend","test_suite":"%%\r\nx = 0:7;\r\ny = 2*x;\r\nw = 3;\r\nys = movingAverage(x,y,w);\r\nassert(isequal(ys,y))\r\n%%\r\nx = 0:9;\r\ny = exp(0.1*x)';\r\nw = 4;\r\nys_correct = [1.0000 1.1089 1.2337 1.3770 1.5420 1.7042 1.8588 2.0339 2.2330 2.4596];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n%%\r\nx = 0:6;\r\ny = sin(x);\r\nw = 1;\r\nys_correct = [0  0.5836  0.6306  0.0979 -0.5249 -0.6650 -0.2794];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n%%\r\nx = 3:11;\r\ny = log(x)';\r\nw = 6;\r\nys_correct = [1.0986  1.3648  1.5664  1.7298  1.8677  2.0463  2.1846  2.2992  2.3979];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":183622,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-01-31T19:50:10.000Z","updated_at":"2019-01-31T20:01:15.000Z","published_at":"2019-01-31T20:00:33.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\u003eA moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\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\u003eA variable window size, w, whenever possible, i.e.\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[w = 3;]]\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\u003emeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\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\u003ereturns a ROW vector of moving average values\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 following inputs:\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[x = [1,2,3,4]; y = [3,5,7,9]; w = 2;]]\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\u003eshould output:\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[ys = [3,5,7,9];]]\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 following inputs:\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[x = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;]]\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\u003eshould output:\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[ys = [2,4.5,6.6,8.5,10];]]\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: the last test case is meant to be a challenge...\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":42856,"title":" Block average","description":"Given a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension. \r\n\r\n* Input: matrix *A* and the size of each sub-matrix *subsz*\r\n* Output: *B = blkavg(A,subsz)*\r\n\r\nExample: \r\n\r\n    A = [2  0  1  3  5  7];\r\n    subsz = [1  2];\r\n    B = [1  2  6];\r\n\r\n\r\nHint: this is related to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42854-crunch-that-matrix Problem 42854. Crunch that matrix!\u003e.\r\n\r\nNext problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42858-block-average-ignoring-nan-values \r\nProblem 42858. Block average ignoring NaN values\u003e","description_html":"\u003cp\u003eGiven a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension.\u003c/p\u003e\u003cul\u003e\u003cli\u003eInput: matrix \u003cb\u003eA\u003c/b\u003e and the size of each sub-matrix \u003cb\u003esubsz\u003c/b\u003e\u003c/li\u003e\u003cli\u003eOutput: \u003cb\u003eB = blkavg(A,subsz)\u003c/b\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e    A = [2  0  1  3  5  7];\r\n    subsz = [1  2];\r\n    B = [1  2  6];\u003c/pre\u003e\u003cp\u003eHint: this is related to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42854-crunch-that-matrix\"\u003eProblem 42854. Crunch that matrix!\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42858-block-average-ignoring-nan-values\"\u003eProblem 42858. Block average ignoring NaN values\u003c/a\u003e\u003c/p\u003e","function_template":"function B = blkavg(A,subsz)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = [2  0  1  3  5  7];\r\nsubsz = [1 2];\r\nB = [1 2 6];\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = [1 2 3 4 5 6 7 8 9].';\r\nsubsz = [3,1];\r\nB = [2 5 8].';\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = [1     1     1     2     2     2\r\n     1     1     1     2     2     2\r\n     3     3     3     4     4     4\r\n     3     3     3     4     4     4];\r\nsubsz = [2   3];\r\nB = [1    2\r\n     3    4];\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = rand(100,300);\r\nsubsz = size(A);\r\nB = mean(A(:));\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nsubsz = [4,6];\r\nB = 10*rand(10,20);\r\nA = repelem(B,subsz(1),subsz(2));\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":46,"test_suite_updated_at":"2016-05-21T16:50:42.000Z","rescore_all_solutions":false,"group_id":24,"created_at":"2016-05-21T02:56:16.000Z","updated_at":"2026-04-01T07:34:01.000Z","published_at":"2016-05-21T15:43:54.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 a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension.\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\u003eInput: matrix\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\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the size of each sub-matrix\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\u003esubsz\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\u003eOutput:\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\u003eB = blkavg(A,subsz)\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[    A = [2  0  1  3  5  7];\\n    subsz = [1  2];\\n    B = [1  2  6];]]\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: this is related to\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/42854-crunch-that-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42854. Crunch that matrix!\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\u003eNext problem:\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/42858-block-average-ignoring-nan-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42858. Block average ignoring NaN values\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":44853,"title":"Mean number of letters per word (Hard)","description":"The previous problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy 44852\u003e.\r\n\r\nGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\r\n\r\n2. There may be redundant spaces in the sentence.\r\n\r\n3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\r\n\r\n4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n  g = 3.792\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n  g = 4.169","description_html":"\u003cp\u003eThe previous problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\"\u003e44852\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\u003c/p\u003e\u003cp\u003e2. There may be redundant spaces in the sentence.\u003c/p\u003e\u003cp\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/p\u003e\u003cp\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\ng = 3.792\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\ng = 4.169\r\n\u003c/pre\u003e","function_template":"function [a,g] = your_fcn_name(c)\r\n    a = 0;\r\n    g = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\n[a,g] = your_fcn_name('');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ,\u0026 ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name([]);\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name('23');\r\nassert(isequal(a,0.000))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' The quick, brown fox jumps over the lazy dog.');\r\nassert(isequal(a,3.889))\r\nassert(isequal(g,3.792))\r\n\r\n%%\r\n[a,g] = your_fcn_name('...another 1 bites the dust...');\r\nassert(isequal(a,3.800))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name('Is ''antidisestablishmentarianism'' the longest (nonscientific) word in the English language ?');\r\nassert(isequal(a,7.700))\r\nassert(isequal(g,5.386))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I ate pudding :-)');\r\nassert(isequal(a,3.667))\r\nassert(isequal(g,2.759))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I hate pudding!');\r\nassert(isequal(a,4.000))\r\nassert(isequal(g,3.037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-02-16T21:25:35.000Z","rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T21:17:39.000Z","updated_at":"2019-05-02T15:18:33.000Z","published_at":"2019-02-16T21:25:35.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\u003eThe previous problem in this series is\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/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44852\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\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\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\u003eYou may make the following assumptions:\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\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\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\u003e2. There may be redundant spaces in the sentence.\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\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a 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\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;\\ng = 3.792]]\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[c = 'Another one bites the dust';\\n\\na = 4.400;\\ng = 4.169]]\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":71,"title":"Read a column of numbers and interpolate missing data","description":"Given an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\r\n\r\nThe first row is always descriptive text. So if the input cell array s is\r\n\r\n s = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\r\n\r\nthen the output variable t is the following row vector.\r\n\r\n t = [-5 19 1 2 3];\r\n\r\nHere's an example of \u003chttp://www.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026dir=data/historical/stdmet/ real-world data\u003e.\r\n","description_html":"\u003cp\u003eGiven an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\u003c/p\u003e\u003cp\u003eThe first row is always descriptive text. So if the input cell array s is\u003c/p\u003e\u003cpre\u003e s = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\u003c/pre\u003e\u003cp\u003ethen the output variable t is the following row vector.\u003c/p\u003e\u003cpre\u003e t = [-5 19 1 2 3];\u003c/pre\u003e\u003cp\u003eHere's an example of \u003ca href = \"http://www.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026dir=data/historical/stdmet/\"\u003ereal-world data\u003c/a\u003e.\u003c/p\u003e","function_template":"function t = read_and_interp(s)\r\n  t = 1;\r\nend","test_suite":"%%\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   1.3'\r\n    '  2   1.12'\r\n    '  3   17'\r\n    '  4   -32'\r\n    '  5   13'\r\n    '  6   4.4'\r\n    '  7   19'};\r\nt_correct = [1.3 1.12 17 -32 13 4.4 19];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n%%\r\n\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   1.3'\r\n    '  2   1.12'\r\n    '  3   17'\r\n    '  4   16'\r\n    '  5   9999'\r\n    '  6   9999'\r\n    '  7   19'};\r\nt_correct = [1.3 1.12 17 16 17 18 19];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n%%\r\n\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\r\nt_correct = [-5 19 1 2 3];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n","published":true,"deleted":false,"likes_count":23,"comments_count":12,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2350,"test_suite_updated_at":"2016-10-26T14:35:53.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:27.000Z","updated_at":"2026-01-12T17:51:44.000Z","published_at":"2012-01-18T01:00:27.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 cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\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 first row is always descriptive text. So if the input cell array s is\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[ s = { ...\\n    'Day  Temp'\\n    '  1   -5'\\n    '  2   19'\\n    '  3   1'\\n    '  4   9999'\\n    '  5   3'};]]\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\u003ethen the output variable t is the following row 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[ t = [-5 19 1 2 3];]]\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\u003eHere's an example of\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.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026amp;dir=data/historical/stdmet/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ereal-world data\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\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":44634,"title":"Basic matrix operations using standard MATLAB commands","description":"Create the matrix:\r\n\r\n 1.0e+15 *\r\n\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\r\n\r\nFind the row vector of all column means\r\n\r\nHint: Use _logspace_ to create the matrix. Avoid looking at the test suite before writing a solution","description_html":"\u003cp\u003eCreate the matrix:\u003c/p\u003e\u003cpre\u003e 1.0e+15 *\u003c/pre\u003e\u003cpre\u003e    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0000    0.0000    0.0000    0.0000    0.0000\r\n    0.0001    0.0010    0.0100    0.1000    1.0000\u003c/pre\u003e\u003cp\u003eFind the row vector of all column means\u003c/p\u003e\u003cp\u003eHint: Use \u003ci\u003elogspace\u003c/i\u003e to create the matrix. Avoid looking at the test suite before writing a solution\u003c/p\u003e","function_template":"function y = matrix_ls_means()\r\n  y = x;\r\nend","test_suite":"%%\r\ny_correct = mean([logspace(1,5,5);logspace(6,10,5);logspace(11,15,5)]);\r\nassert(isequal(matrix_ls_means(),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":171559,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-05-09T05:37:01.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-05-09T05:32:41.000Z","updated_at":"2026-02-17T08:19:25.000Z","published_at":"2018-05-09T05:35:49.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\u003eCreate the matrix:\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[ 1.0e+15 *\\n\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0000    0.0000    0.0000    0.0000    0.0000\\n    0.0001    0.0010    0.0100    0.1000    1.0000]]\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\u003eFind the row vector of all column means\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: Use\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:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003elogspace\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e to create the matrix. Avoid looking at the test suite before writing a solution\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":1723,"title":"Square wave average calculation","description":"Given its peak and duty cycle, calculate avg value of square wave","description_html":"\u003cp\u003eGiven its peak and duty cycle, calculate avg value of square wave\u003c/p\u003e","function_template":"function avg = your_fcn_name(peak,duty)\r\n  y = x;\r\nend","test_suite":"%%\r\npeak = 5;\r\nduty = 0.6\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(peak,duty),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":14448,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":131,"test_suite_updated_at":"2013-07-18T07:04:09.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-18T07:01:55.000Z","updated_at":"2026-03-09T20:58:01.000Z","published_at":"2013-07-18T07:04: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 its peak and duty cycle, calculate avg value of square wave\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":42732,"title":"Average Grade","description":"Given a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.","description_html":"\u003cp\u003eGiven a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.\u003c/p\u003e","function_template":"function y = ave_grade(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [65 77 83 92 86];\r\ny_correct = 80.6;\r\nassert(isequal(ave_grade(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":62985,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":182,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-02-18T16:16:41.000Z","updated_at":"2026-03-31T09:52:16.000Z","published_at":"2016-02-18T16:17: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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 a 1x5 vector presents the grades of a student on five tests. Calculate the average grade of that student.\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":42351,"title":"Average valid values of arrays","description":"Given a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\r\n\r\n  x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\n  minValue = -10;\r\n  maxValue = 10;\r\n  y = validAverage(x, minValue, maxValue) = -3.2\r\n\r\nTo keep it simple, let's assume minValue and maxValue are within the array range.","description_html":"\u003cp\u003eGiven a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminValue = -10;\r\nmaxValue = 10;\r\ny = validAverage(x, minValue, maxValue) = -3.2\r\n\u003c/pre\u003e\u003cp\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\u003c/p\u003e","function_template":"function y = validAverage(x, minV, maxV)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = 1;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\r\nminV = -10;\r\nmaxV = 10;\r\ny_correct = -3.2;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))\r\n\r\n%%\r\nx=1:100;\r\nminV=20;\r\nmaxV=80;\r\ny_correct = 50;\r\nassert(isequal(round(validAverage(x,minV, maxV),4),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":44306,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":61,"test_suite_updated_at":"2015-06-01T21:37:45.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-06-01T21:16:24.000Z","updated_at":"2026-02-17T15:29:50.000Z","published_at":"2015-06-01T21:25:20.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 a 1D array (column or row vector), compute the average of valid values. Valid values are defined via two thresholds: minValue and maxValue. Example:\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[x = [-1 -5.4 14.6 20.9 25.5 -22.4 18 15.5 -33.7 -38.1];\\nminValue = -10;\\nmaxValue = 10;\\ny = validAverage(x, minValue, maxValue) = -3.2]]\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\u003eTo keep it simple, let's assume minValue and maxValue are within the array range.\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":1216,"title":"Mean ignoring NaNs","description":"Define a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).","description_html":"\u003cp\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\u003c/p\u003e","function_template":"function y=average(x,d)\r\ny=0;\r\n","test_suite":"%%\r\nx=[1 5 9;2 6 10;3 nan 11;nan nan nan];\r\ny_correct=[2 5.5 10];\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[5;6;7;nan];\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=x;\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=cat(3,[1 5 9;NaN 6 10;NaN 7 NaN;4 8 12],...\r\n [13 17 21;14 18 22;15 19 NaN;16 20 24]);\r\ny_correct=cat(3,[15 39 62]/6,[87 111 134]/6);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=cat(3,[5;8;7;8],[17;18;17;20]);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=[7 11 15;14 12 16;15 13 NaN;10 14 18];\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n%%\r\nx=zeros(2,1,0);\r\ny_correct=mean(x);\r\ny=average(x);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny=average(x,1);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,2);\r\ny=average(x,2);\r\nassert(isequalwithequalnans(y,y_correct))\r\ny_correct=mean(x,3);\r\ny=average(x,3);\r\nassert(isequalwithequalnans(y,y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":245,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":52,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-01-19T20:54:55.000Z","updated_at":"2026-03-05T14:17:40.000Z","published_at":"2013-01-19T21:44:47.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eDefine a function that behaves in the same way as mean(x) and mean(x,d) except that it ignores NaNs (unless all of the values being averaged are NaNs, in which case the result for those values should be NaN).\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":44852,"title":"Mean number of letters per word (Easy)","description":"Given a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. All characters in the array are either letters or spaces.\r\n\r\n2. There are no redundant spaces.\r\n\r\n3. Except for spaces, there is no punctuation in the sentence.\r\n\r\n4. There will always be at least two words in the sentence.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n\r\nThe next problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard Problem 44853\u003e.","description_html":"\u003cp\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. All characters in the array are either letters or spaces.\u003c/p\u003e\u003cp\u003e2. There are no redundant spaces.\u003c/p\u003e\u003cp\u003e3. Except for spaces, there is no punctuation in the sentence.\u003c/p\u003e\u003cp\u003e4. There will always be at least two words in the sentence.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\n\u003c/pre\u003e\u003cp\u003eThe next problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\"\u003eProblem 44853\u003c/a\u003e.\u003c/p\u003e","function_template":"function a = your_fcn_name(c)\r\n    a = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Hello world'),5.000))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('The quick brown fox jumps over the lazy dog'),3.889))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Another one bites the dust'),4.400))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('Antidisestablishmentarianism is the longest nonscientific word in the English language'),7.700))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I ate pudding'),3.667))\r\n\r\n%%\r\nassert(isequal(your_fcn_name('I hate pudding'),4.000))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T20:34:25.000Z","updated_at":"2026-03-24T12:02:15.000Z","published_at":"2019-02-16T21:25: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:r\u003e\u003cw:t\u003eGiven a character array, s, representing a sentence, return a, the arithmetic mean of the number of letters per word in the given sentence. Round your answer to three decimal digits.\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\u003eYou may make the following assumptions:\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\u003e1. All characters in the array are either letters or spaces.\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\u003e2. There are no redundant spaces.\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\u003e3. Except for spaces, there is no punctuation in the sentence.\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\u003e4. There will always be at least two words in the sentence.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;]]\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[c = 'Another one bites the dust';\\n\\na = 4.400;]]\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 next problem in this series is\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/matlabcentral/cody/problems/44853-mean-number-of-letters-per-word-hard\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 44853\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\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":106,"title":"Weighted average","description":"Given two lists of numbers, determine the weighted average as follows\r\nExample\r\n [1 2 3] and [10 15 20]\r\nshould result in\r\n 33.3333  (1*10 + 2*15 + 3*20)/3","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.4333px; min-height: 0px; white-space: normal; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, monospace; font-style: normal; font-size: 14px; font-weight: 400; text-decoration: rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"block-size: 142.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 71.4333px; transform-origin: 407px 71.4333px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 220.5px 8px; transform-origin: 220.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven two lists of numbers, determine the weighted average as follows\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 26.5px 8px; transform-origin: 26.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 92px 8.5px; tab-size: 4; transform-origin: 92px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; \"\u003e [1 2 3] and \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 40px 8.5px; text-decoration: none; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 40px 8.5px; \"\u003e[10 15 20]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 48px 8px; transform-origin: 48px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eshould result in\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 20.4333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 128px 8.5px; tab-size: 4; transform-origin: 128px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 33.3333  (1*10 + 2*15 + 3*20)/3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = weighted_average(x,w)\r\n  y =\r\nend","test_suite":"%%\r\nx = [1 2 3];\r\nw = [10 15 20];\r\ny_correct = 100/3;\r\nassert(isequal(weighted_average(x,w),y_correct))\r\n\r\n%%\r\nx = [0 -2 3];\r\nw = [10 0 10];\r\ny_correct = 10;\r\nassert(isequal(weighted_average(x,w),y_correct))","published":true,"deleted":false,"likes_count":34,"comments_count":24,"created_by":140,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":6714,"test_suite_updated_at":"2014-10-09T20:20:08.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T01:16:10.000Z","updated_at":"2026-03-16T05:03:07.000Z","published_at":"2012-01-26T01:18:12.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two lists of numbers, determine the weighted average as follows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\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[ [1 2 3] and [10 15 20]]]\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eshould result in\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[ 33.3333  (1*10 + 2*15 + 3*20)/3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2349,"title":"Elements with highest local average","description":"Input v is a row vector such that length(v)\u003e3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\r\n\r\nExample:\r\n\r\nInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\r\n\r\nOutput: vOut=[7 8 9];\r\n\r\nThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.","description_html":"\u003cp\u003eInput v is a row vector such that length(v)\u0026gt;3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\u003c/p\u003e\u003cp\u003eOutput: vOut=[7 8 9];\u003c/p\u003e\u003cp\u003eThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n\r\n\r\n\r\n\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5 6 7 8 9];\r\ny_correct = [7 8 9];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = [1 2 3];\r\ny_correct = [1 2 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [0 0 0];\r\ny_correct = [0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [3 3 3 1 1 1 2 3 4];\r\ny_correct = [3 3 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n\r\n%%\r\nx = 1000:-1:1;\r\ny_correct = [1000 999 998];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":98,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":39,"created_at":"2014-06-05T13:41:48.000Z","updated_at":"2026-04-02T08:10:41.000Z","published_at":"2014-06-05T13:43:55.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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"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\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\u003eInput v is a row vector such that length(v)\u0026gt;3. Consider a sliding window of length 3 that is used to calculate the local average of the elements. Return the three consecutive elements that maximizes such average according to the order they appear in v in a row vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: v=[1 2 3 4 5 6 7 8 9 -3 0 1];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput: vOut=[7 8 9];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe consecutive elements [7 8 9] have the highest average among all such consecutive sub-vectors. For a tie case, return the first triplet according to appearance in v.\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":44816,"title":"Word Distance - Average Sort","description":"Based on the method of \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44815-word-distance-sum this problem\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if \r\n\r\n str_arr = {'jazz','cab','tree'}\r\n\r\nthen \r\n\r\n d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]\r\n\r\nwhich would result in the following sorted order:\r\n\r\n str_arr_sort = {'cab','tree','jazz'}\r\n\r\nRemember that the method is case insensitive. See the test suite for examples.","description_html":"\u003cp\u003eBased on the method of \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44815-word-distance-sum\"\u003ethis problem\u003c/a\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if\u003c/p\u003e\u003cpre\u003e str_arr = {'jazz','cab','tree'}\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre\u003e d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]\u003c/pre\u003e\u003cp\u003ewhich would result in the following sorted order:\u003c/p\u003e\u003cpre\u003e str_arr_sort = {'cab','tree','jazz'}\u003c/pre\u003e\u003cp\u003eRemember that the method is case insensitive. See the test suite for examples.\u003c/p\u003e","function_template":"function d = word_distance_sort(str_arr)\r\n d = 1;\r\nend","test_suite":"%%\r\nassert(isequal(word_distance_sort({'jazz','cab','tree'}),{'cab','tree','jazz'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'first','second','third'}),{'first','second','third'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'the','longest','words','supercede','some','of','the','shortest'}), ...\r\n\t{'some','longest','of','the','the','supercede','shortest','words'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'one','TWO','Three','FouR','fiVe','six','sEvEn','EiGHt','NINe','ten'}), ...\r\n\t{'one','TWO','EiGHt','FouR','NINe','Three','ten','fiVe','six','sEvEn'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'Why','is','it','that','this','does','not','work','as','expected'}), ...\r\n\t{'not','work','is','it','this','does','as','expected','that','Why'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'set','of','very','short','words','for','this','test','case'}), ...\r\n\t{'for','of','short','this','test','words','case','very','set'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'iron','zinc','carbon','molybdenum','praseodymium','silicon'}), ...\r\n\t{'iron','silicon','molybdenum','carbon','zinc','praseodymium'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'crazier','craziest','crazy'}), ...\r\n\t{'crazy','craziest','crazier'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'this','test','case','with','only','four','each','word'}), ...\r\n\t{'each','only','four','this','word','test','case','with'}))\r\n\r\n%%\r\nassert(isequal(word_distance_sort({'largest','smallest','sourest','sweetest'}), ...\r\n\t{'sourest','smallest','largest','sweetest'}))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":26769,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":15,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":65,"created_at":"2019-01-02T15:43:24.000Z","updated_at":"2025-11-21T14:57:55.000Z","published_at":"2019-01-09T15:06:52.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\u003eBased on the method of\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/matlabcentral/cody/problems/44815-word-distance-sum\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ethis problem\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, write a function to calculate the letter distance for a set of words and then return the sorted set of words based on their distances, in ascending order. However, their distances will now be normalized by the number of characters in each word. For example, if\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[ str_arr = {'jazz','cab','tree'}]]\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\u003ethen\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[ d = [(9+25+0)/4, (2+1)/3, (2+13+0)/4] = [34/4, 3/3, 15/4] = [8.5, 1, 3.75]]]\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\u003ewhich would result in the following sorted order:\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[ str_arr_sort = {'cab','tree','jazz'}]]\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\u003eRemember that the method is case insensitive. See the test suite for examples.\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":44844,"title":"Moving average ","description":"A moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\r\n\r\nA variable window size, w, whenever possible, i.e.\r\n\r\n  w = 3;\r\n\r\nmeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\r\n\r\n\r\nreturns a ROW vector of moving average values\r\n\r\nThe following inputs: \r\n\r\n  x = [1,2,3,4]; y = [3,5,7,9]; w = 2;\r\n\r\nshould output:\r\n\r\n  ys = [3,5,7,9];\r\n\r\nThe following inputs: \r\n\r\n  x = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;\r\n\r\nshould output:\r\n\r\n  ys = [2,4.5,6.6,8.5,10];\r\n\r\n\r\nNote: the last test case is meant to be a challenge...","description_html":"\u003cp\u003eA moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\u003c/p\u003e\u003cp\u003eA variable window size, w, whenever possible, i.e.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ew = 3;\r\n\u003c/pre\u003e\u003cp\u003emeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\u003c/p\u003e\u003cp\u003ereturns a ROW vector of moving average values\u003c/p\u003e\u003cp\u003eThe following inputs:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [1,2,3,4]; y = [3,5,7,9]; w = 2;\r\n\u003c/pre\u003e\u003cp\u003eshould output:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eys = [3,5,7,9];\r\n\u003c/pre\u003e\u003cp\u003eThe following inputs:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;\r\n\u003c/pre\u003e\u003cp\u003eshould output:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eys = [2,4.5,6.6,8.5,10];\r\n\u003c/pre\u003e\u003cp\u003eNote: the last test case is meant to be a challenge...\u003c/p\u003e","function_template":"function ys = movingAverage(x,y,w)\r\n  ys = y;\r\nend","test_suite":"%%\r\nx = 0:7;\r\ny = 2*x;\r\nw = 3;\r\nys = movingAverage(x,y,w);\r\nassert(isequal(ys,y))\r\n%%\r\nx = 0:9;\r\ny = exp(0.1*x)';\r\nw = 4;\r\nys_correct = [1.0000 1.1089 1.2337 1.3770 1.5420 1.7042 1.8588 2.0339 2.2330 2.4596];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n%%\r\nx = 0:6;\r\ny = sin(x);\r\nw = 1;\r\nys_correct = [0  0.5836  0.6306  0.0979 -0.5249 -0.6650 -0.2794];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n%%\r\nx = 3:11;\r\ny = log(x)';\r\nw = 6;\r\nys_correct = [1.0986  1.3648  1.5664  1.7298  1.8677  2.0463  2.1846  2.2992  2.3979];\r\nys = movingAverage(x,y,w);\r\nassert(norm(ys_correct-ys)\u003c.001)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":183622,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":5,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2019-01-31T19:50:10.000Z","updated_at":"2019-01-31T20:01:15.000Z","published_at":"2019-01-31T20:00:33.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\u003eA moving average function that returns an array that is equal in length to the input arrays (which can be row or column)\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\u003eA variable window size, w, whenever possible, i.e.\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[w = 3;]]\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\u003emeans to use 3 data points on both sides of the point of interest (averaging 7 points total)\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\u003ereturns a ROW vector of moving average values\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 following inputs:\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[x = [1,2,3,4]; y = [3,5,7,9]; w = 2;]]\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\u003eshould output:\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[ys = [3,5,7,9];]]\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 following inputs:\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[x = [1,2,3,4,5]; y = [2,5.5,6,9.5,10]; w = 3;]]\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\u003eshould output:\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[ys = [2,4.5,6.6,8.5,10];]]\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: the last test case is meant to be a challenge...\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":42856,"title":" Block average","description":"Given a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension. \r\n\r\n* Input: matrix *A* and the size of each sub-matrix *subsz*\r\n* Output: *B = blkavg(A,subsz)*\r\n\r\nExample: \r\n\r\n    A = [2  0  1  3  5  7];\r\n    subsz = [1  2];\r\n    B = [1  2  6];\r\n\r\n\r\nHint: this is related to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42854-crunch-that-matrix Problem 42854. Crunch that matrix!\u003e.\r\n\r\nNext problem: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42858-block-average-ignoring-nan-values \r\nProblem 42858. Block average ignoring NaN values\u003e","description_html":"\u003cp\u003eGiven a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension.\u003c/p\u003e\u003cul\u003e\u003cli\u003eInput: matrix \u003cb\u003eA\u003c/b\u003e and the size of each sub-matrix \u003cb\u003esubsz\u003c/b\u003e\u003c/li\u003e\u003cli\u003eOutput: \u003cb\u003eB = blkavg(A,subsz)\u003c/b\u003e\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e    A = [2  0  1  3  5  7];\r\n    subsz = [1  2];\r\n    B = [1  2  6];\u003c/pre\u003e\u003cp\u003eHint: this is related to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42854-crunch-that-matrix\"\u003eProblem 42854. Crunch that matrix!\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eNext problem: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42858-block-average-ignoring-nan-values\"\u003eProblem 42858. Block average ignoring NaN values\u003c/a\u003e\u003c/p\u003e","function_template":"function B = blkavg(A,subsz)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = [2  0  1  3  5  7];\r\nsubsz = [1 2];\r\nB = [1 2 6];\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = [1 2 3 4 5 6 7 8 9].';\r\nsubsz = [3,1];\r\nB = [2 5 8].';\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = [1     1     1     2     2     2\r\n     1     1     1     2     2     2\r\n     3     3     3     4     4     4\r\n     3     3     3     4     4     4];\r\nsubsz = [2   3];\r\nB = [1    2\r\n     3    4];\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nA = rand(100,300);\r\nsubsz = size(A);\r\nB = mean(A(:));\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)\r\n\r\n%%\r\nsubsz = [4,6];\r\nB = 10*rand(10,20);\r\nA = repelem(B,subsz(1),subsz(2));\r\nassert(norm(B-blkavg(A,subsz)) \u003c 1e-10)","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":46,"test_suite_updated_at":"2016-05-21T16:50:42.000Z","rescore_all_solutions":false,"group_id":24,"created_at":"2016-05-21T02:56:16.000Z","updated_at":"2026-04-01T07:34:01.000Z","published_at":"2016-05-21T15:43:54.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 a matrix, calculate the block average of each disjoint sub-matrix of the same size. Assume that the size of the matrix along each dimension is an integer multiple of the size of the sub-matrix along the same dimension.\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\u003eInput: matrix\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\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and the size of each sub-matrix\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\u003esubsz\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\u003eOutput:\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\u003eB = blkavg(A,subsz)\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[    A = [2  0  1  3  5  7];\\n    subsz = [1  2];\\n    B = [1  2  6];]]\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: this is related to\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/42854-crunch-that-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42854. Crunch that matrix!\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\u003eNext problem:\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/42858-block-average-ignoring-nan-values\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42858. Block average ignoring NaN values\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":44853,"title":"Mean number of letters per word (Hard)","description":"The previous problem in this series is \u003chttps://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy 44852\u003e.\r\n\r\nGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\r\n\r\nYou may make the following assumptions:\r\n\r\n1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\r\n\r\n2. There may be redundant spaces in the sentence.\r\n\r\n3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\r\n\r\n4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\r\n\r\nExample:\r\n\r\n  c = 'The quick brown fox jumps over the lazy dog';\r\n  \r\n  a = 3.889;\r\n  g = 3.792\r\n\r\nExample:\r\n\r\n  c = 'Another one bites the dust';\r\n  \r\n  a = 4.400;\r\n  g = 4.169","description_html":"\u003cp\u003eThe previous problem in this series is \u003ca href = \"https://www.mathworks.com/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\"\u003e44852\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\u003c/p\u003e\u003cp\u003eYou may make the following assumptions:\u003c/p\u003e\u003cp\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\u003c/p\u003e\u003cp\u003e2. There may be redundant spaces in the sentence.\u003c/p\u003e\u003cp\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a word.\u003c/p\u003e\u003cp\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'The quick brown fox jumps over the lazy dog';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 3.889;\r\ng = 3.792\r\n\u003c/pre\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ec = 'Another one bites the dust';\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ea = 4.400;\r\ng = 4.169\r\n\u003c/pre\u003e","function_template":"function [a,g] = your_fcn_name(c)\r\n    a = 0;\r\n    g = 0;\r\nend","test_suite":"%%\r\nfiletext = fileread('your_fcn_name.m');\r\nassert(isempty(strfind(filetext,'eval')))\r\nassert(isempty(strfind(filetext,'echo')))\r\nassert(isempty(strfind(filetext,'switch')))\r\n\r\n%%\r\n[a,g] = your_fcn_name('');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' ,\u0026 ');\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name([]);\r\nassert(isempty(a))\r\nassert(isempty(g))\r\n\r\n%%\r\n[a,g] = your_fcn_name('23');\r\nassert(isequal(a,0.000))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name(' The quick, brown fox jumps over the lazy dog.');\r\nassert(isequal(a,3.889))\r\nassert(isequal(g,3.792))\r\n\r\n%%\r\n[a,g] = your_fcn_name('...another 1 bites the dust...');\r\nassert(isequal(a,3.800))\r\nassert(isequal(g,0.000))\r\n\r\n%%\r\n[a,g] = your_fcn_name('Is ''antidisestablishmentarianism'' the longest (nonscientific) word in the English language ?');\r\nassert(isequal(a,7.700))\r\nassert(isequal(g,5.386))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I ate pudding :-)');\r\nassert(isequal(a,3.667))\r\nassert(isequal(g,2.759))\r\n\r\n%%\r\n[a,g] = your_fcn_name('I hate pudding!');\r\nassert(isequal(a,4.000))\r\nassert(isequal(g,3.037))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":15521,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":"2019-02-16T21:25:35.000Z","rescore_all_solutions":false,"group_id":65,"created_at":"2019-02-16T21:17:39.000Z","updated_at":"2019-05-02T15:18:33.000Z","published_at":"2019-02-16T21:25:35.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\u003eThe previous problem in this series is\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/matlabcentral/cody/problems/44852-mean-number-of-letters-per-word-easy\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e44852\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\u003eGiven a character array, s, representing a sentence, return a and g, the arithmetic and geometric means, respectively, of the number of letters per word in the given sentence. Round your answer to three decimal digits.\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\u003eYou may make the following assumptions:\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\u003e1. Not all characters in the array are either letters or spaces. There may also be numeric characters, as well as punctuation.\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\u003e2. There may be redundant spaces in the sentence.\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\u003e3. Punctuation does not count as a letter and cannot constitute a word in itself. Numbers also do not count as letters, but can constitute a 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\u003e4. There can be any number of characters and/or words in the sentence, including zero. When there are zero words in the sentence, return empty matrices for a and g.\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[c = 'The quick brown fox jumps over the lazy dog';\\n\\na = 3.889;\\ng = 3.792]]\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[c = 'Another one bites the dust';\\n\\na = 4.400;\\ng = 4.169]]\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":71,"title":"Read a column of numbers and interpolate missing data","description":"Given an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\r\n\r\nThe first row is always descriptive text. So if the input cell array s is\r\n\r\n s = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\r\n\r\nthen the output variable t is the following row vector.\r\n\r\n t = [-5 19 1 2 3];\r\n\r\nHere's an example of \u003chttp://www.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026dir=data/historical/stdmet/ real-world data\u003e.\r\n","description_html":"\u003cp\u003eGiven an input cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\u003c/p\u003e\u003cp\u003eThe first row is always descriptive text. So if the input cell array s is\u003c/p\u003e\u003cpre\u003e s = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\u003c/pre\u003e\u003cp\u003ethen the output variable t is the following row vector.\u003c/p\u003e\u003cpre\u003e t = [-5 19 1 2 3];\u003c/pre\u003e\u003cp\u003eHere's an example of \u003ca href = \"http://www.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026dir=data/historical/stdmet/\"\u003ereal-world data\u003c/a\u003e.\u003c/p\u003e","function_template":"function t = read_and_interp(s)\r\n  t = 1;\r\nend","test_suite":"%%\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   1.3'\r\n    '  2   1.12'\r\n    '  3   17'\r\n    '  4   -32'\r\n    '  5   13'\r\n    '  6   4.4'\r\n    '  7   19'};\r\nt_correct = [1.3 1.12 17 -32 13 4.4 19];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n%%\r\n\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   1.3'\r\n    '  2   1.12'\r\n    '  3   17'\r\n    '  4   16'\r\n    '  5   9999'\r\n    '  6   9999'\r\n    '  7   19'};\r\nt_correct = [1.3 1.12 17 16 17 18 19];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n%%\r\n\r\ns = { ...\r\n    'Day  Temp'\r\n    '  1   -5'\r\n    '  2   19'\r\n    '  3   1'\r\n    '  4   9999'\r\n    '  5   3'};\r\nt_correct = [-5 19 1 2 3];\r\nassert(isequal(read_and_interp(s),t_correct));\r\n\r\n","published":true,"deleted":false,"likes_count":23,"comments_count":12,"created_by":1,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2350,"test_suite_updated_at":"2016-10-26T14:35:53.000Z","rescore_all_solutions":false,"group_id":2,"created_at":"2012-01-18T01:00:27.000Z","updated_at":"2026-01-12T17:51:44.000Z","published_at":"2012-01-18T01:00:27.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 cell array of strings s, pick out the second column and turn it into a row vector of data. Missing data will be indicated by the number 9999. If you encounter missing data, you should perform linear interpolation to the nearest accurate data points (missing data will not occur in the first or last element).\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 first row is always descriptive text. So if the input cell array s is\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[ s = { ...\\n    'Day  Temp'\\n    '  1   -5'\\n    '  2   19'\\n    '  3   1'\\n    '  4   9999'\\n    '  5   3'};]]\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\u003ethen the output variable t is the following row 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[ t = [-5 19 1 2 3];]]\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\u003eHere's an example of\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.ndbc.noaa.gov/view_text_file.php?filename=41nt1h2008.txt.gz\u0026amp;dir=data/historical/stdmet/\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ereal-world data\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\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:\"average\"","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:\"average\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"average\"","","\"","average","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd718\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d82fd678\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d82fcd18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd998\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d82fd8f8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d82fd858\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d82fd7b8\u003e":"tag:\"average\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd7b8\u003e":"tag:\"average\""},"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":"search","password":"J3bGPZzQ7asjJcCk","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:\"average\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"average\"","","\"","average","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd718\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f74d82fd678\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f74d82fcd18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd998\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f74d82fd8f8\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f74d82fd858\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f74d82fd7b8\u003e":"tag:\"average\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f74d82fd7b8\u003e":"tag:\"average\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44634,"difficulty_rating":"easy"},{"id":1723,"difficulty_rating":"easy"},{"id":42732,"difficulty_rating":"easy"},{"id":42351,"difficulty_rating":"easy"},{"id":1216,"difficulty_rating":"easy"},{"id":44852,"difficulty_rating":"easy"},{"id":106,"difficulty_rating":"easy-medium"},{"id":2349,"difficulty_rating":"easy-medium"},{"id":44816,"difficulty_rating":"easy-medium"},{"id":44844,"difficulty_rating":"easy-medium"},{"id":42856,"difficulty_rating":"medium"},{"id":44853,"difficulty_rating":"medium"},{"id":71,"difficulty_rating":"medium-hard"}]}}