{"group":{"group":{"id":21,"name":"Indexing III","lockable":false,"created_at":"2017-03-15T17:22:57.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Even more problems that require operating on a subset of elements from a vector or matrix.","is_default":false,"created_by":26769,"badge_id":35,"featured":false,"trending":false,"solution_count_in_trending_period":30,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":400,"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":"{\"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\u003eEven more problems that require operating on a subset of elements from a vector or matrix.\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\"}]}","description_html":"\u003cdiv style = \"text-align: start; line-height: normal; 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: none solid rgb(0, 0, 0); white-space: normal; \"\u003e\u003cdiv style=\"display: block; min-width: 0px; padding-top: 0px; perspective-origin: 289.5px 21px; transform-origin: 289.5px 21px; \"\u003e\u003cdiv style=\"font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-bottom: 9px; margin-left: 4px; margin-right: 10px; margin-top: 2px; text-align: left; white-space: pre-wrap; perspective-origin: 266.5px 21px; transform-origin: 266.5px 21px; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"display: inline; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eEven more problems that require operating on a subset of elements from a vector or matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","published_at":"2019-05-08T19:55:54.000Z"},"current_player":null},"problems":[{"id":2561,"title":"expand intervals vol.3","description":"This is the next problem after \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2560 2560\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\r\n\r\nGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\r\n\r\nSee also problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e","description_html":"\u003cp\u003eThis is the next problem after \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2560\"\u003e2560\u003c/a\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\u003c/p\u003e\u003cp\u003eSee also problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(round(x));\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [5 1 3 9 32 24];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 300 100];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.1:9; -9:9.5];\r\nbounds = temp(:)';\r\nelements = -11:9;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.21:11; -8.7:10];\r\nbounds = temp(:)';\r\nelements = [-11:0, 7:10];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:2.599:9; -9:2.601:11];\r\nbounds = temp(:)';\r\nelements = [-11:-7, -5:-2, 0:6, 8:9];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10.8 10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) \r\n\r\n%%\r\nbounds = [10.8 -10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) ","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":80,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T10:51:42.000Z","updated_at":"2026-03-16T15:51:29.000Z","published_at":"2014-09-08T10:51:42.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\u003eThis is the next problem after\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.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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.co.uk/matlabcentral/cody/problems/2560\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2560\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\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 row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\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\u003eSee also 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.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\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":2456,"title":"remove single elements","description":"Given a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\r\nExample:\r\nInput: vec = [2 2 1 2 3 4 1 2];\r\nOutput: [2 2 1 2 1 2];\r\nLoops are not allowed.","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: 153.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 76.9333px; transform-origin: 407px 76.9333px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; 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 21px; text-align: left; transform-origin: 384px 21px; 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: 378px 8px; transform-origin: 378px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\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: 28.5px 8px; transform-origin: 28.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: 40.8667px; 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 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 124px 8.5px; tab-size: 4; transform-origin: 124px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eInput: vec = [2 2 1 2 3 4 1 2];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eOutput: [2 2 1 2 1 2];\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: 71.5px 8px; transform-origin: 71.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLoops are not allowed.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function[ans]=removeSingle(v)\r\n\r\n\r\nend","test_suite":"%%\r\n\r\nvec = [2 2 1 2 3 4 1 2];\r\nout = [2     2     1     2     1     2];\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n%%\r\nvec = ones(1,10000);\r\nout = vec;\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n\r\n%%\r\nvec = [];\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = [1 2 3 4 5];\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = primes(10);\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = [4 4 5 5 1 1 2 2];\r\nout = vec;\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n\r\n%%\r\nvec = [4 1 4];\r\nout = [4 4];\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n%%\r\nfiletext = fileread('removeSingle.m');\r\nillegal = contains(filetext, 'for ') || contains(filetext, 'while '); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":17203,"edited_by":223089,"edited_at":"2022-10-22T18:43:22.000Z","deleted_by":null,"deleted_at":null,"solvers_count":131,"test_suite_updated_at":"2022-10-22T18:43:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-07-20T15:07:45.000Z","updated_at":"2026-03-04T04:36:47.000Z","published_at":"2014-07-20T15:07:45.000Z","restored_at":null,"restored_by":null,"spam":null,"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 a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\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[Input: vec = [2 2 1 2 3 4 1 2];\\nOutput: [2 2 1 2 1 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLoops are not allowed.\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":2091,"title":"return row and column indices given 2 values which define a range","description":"Inspired by problem http://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\r\nA little complication: let your function be able to deal with a random order of the input arguments.\r\nIf all input arguments have the same size, assume that the first argument is the \"matrix\" with value(s).\r\nDon't use \"find\" and don't use \"regexp\".","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: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 76.5px; transform-origin: 407px 76.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 62px 8px; transform-origin: 62px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by problem\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\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: 303.5px 8px; transform-origin: 303.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA little complication: let your function be able to deal with a random order of the input arguments.\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: 316px 8px; transform-origin: 316px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf all input arguments have the same size, assume that the first argument is the \"matrix\" with value(s).\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: 124px 8px; transform-origin: 124px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDon't use \"find\" and don't use \"regexp\".\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [rowidx,colidx] = RCMatrixIndices(x1,x2,x3)\r\n  A=1;\r\nuplim=1;\r\nlowlim=1;\r\nend","test_suite":"%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R1,C1]=RCMatrixIndices(x1,x2,x3);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R1,fr1),isequal(C1,fc1)))\r\n%%\r\nfiletext = fileread('RCMatrixIndices.m');\r\nassert(isempty(strfind(filetext, 'find'))\u0026isempty(strfind(filetext, 'regexp'))...\r\n    \u0026isempty(strfind(filetext, 'str2num')))\r\n%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R2,C2]=RCMatrixIndices(x2,x1, x3);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R2,fr1),isequal(C2,fc1)))\r\n%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R3,C3]=RCMatrixIndices(x1,x3,x2);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R3,fr1),isequal(C3,fc1)))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=3;\r\nuplim=9;\r\n[R4,C4]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(length(A(4*(C4-1)+R4))==16)\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=4;\r\nuplim=9;\r\n%extract only 8\r\n[R5,C5]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(all(A(4*(C5-1)+R5)==8))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=4;\r\nuplim=7;\r\n[R6,C6]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(isempty(R6),isempty(C6)))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=2;\r\nuplim=7;\r\n[R7,C7]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(all(A(4*(C7-1)+R7)==3),length(R7==10)))\r\n%%\r\nA=1;\r\nlowlim=1;\r\nuplim=1;\r\n[R8,C8]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(isempty(R8),isempty(C8)))\r\n%%\r\nA=1;\r\nlowlim=1;\r\nuplim=2;\r\n[R9,C9]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(R9==1,C9==1))","published":true,"deleted":false,"likes_count":3,"comments_count":7,"created_by":20079,"edited_by":223089,"edited_at":"2022-11-21T11:00:01.000Z","deleted_by":null,"deleted_at":null,"solvers_count":78,"test_suite_updated_at":"2022-11-21T11:00:01.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-01-07T08:32:32.000Z","updated_at":"2026-03-09T19:07:20.000Z","published_at":"2014-01-07T12:29:47.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eInspired by 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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\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\u003eA little complication: let your function be able to deal with a random order of the input arguments.\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\u003eIf all input arguments have the same size, assume that the first argument is the \\\"matrix\\\" with value(s).\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\u003eDon't use \\\"find\\\" and don't use \\\"regexp\\\".\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":2560,"title":"expand intervals vol.2","description":"Similar to problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\r\n\r\nGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\r\n\r\nSee also problems \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2561 2561\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e.","description_html":"\u003cp\u003eSimilar to problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\u003c/p\u003e\u003cp\u003eSee also problems \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2561\"\u003e2561\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(x);\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 100 300];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:9; -9:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T09:17:06.000Z","updated_at":"2026-03-09T19:01:56.000Z","published_at":"2014-09-08T09:17:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to 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.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\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 row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\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\u003eSee also problems\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.co.uk/matlabcentral/cody/problems/2561\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2561\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\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.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\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":2545,"title":"compress sequence into intervals","description":"You're given a row vector of monotonically increasing integers most of which are consecutive. Find the upper and lower bounds of each run in that vector and return that as a row vector of intervals.\r\n\r\nNote: this is the inverse of \u003chttp://www.mathworks.com/matlabcentral/cody/problems/2528 problem 2528 - Expand intervals\u003e.","description_html":"\u003cp\u003eYou're given a row vector of monotonically increasing integers most of which are consecutive. Find the upper and lower bounds of each run in that vector and return that as a row vector of intervals.\u003c/p\u003e\u003cp\u003eNote: this is the inverse of \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/2528\"\u003eproblem 2528 - Expand intervals\u003c/a\u003e.\u003c/p\u003e","function_template":"function bounds = CompressSequence(sequence)\r\n  %??\r\nend","test_suite":"%%\r\nsequence = [1 2 3 4 5 7 8 9 24 25 26 27 28 29 30 31 32];\r\nbounds = [1 5 7 9 24 32];\r\nassert(isequal(CompressSequence(sequence), bounds))\r\n\r\n%%\r\nsequence = [100:200 300:400];\r\nbounds = [100 200 300 400];\r\nassert(isequal(CompressSequence(sequence), bounds))\r\n\r\n\r\n%%\r\nsequence = -10:10;\r\nbounds = [-10 10];\r\nassert(isequal(CompressSequence(sequence), bounds))\r\n\r\n%%\r\nsequence = [9 11];\r\nbounds = [9 9 11 11];\r\nassert(isequal(CompressSequence(sequence), bounds))\r\n\r\n%%\r\nsequence = 1:2:99;\r\ntemp = [1:2:99; 1:2:99];\r\nbounds = temp(:)';\r\nassert(isequal(CompressSequence(sequence), bounds))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":99,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-03T12:22:45.000Z","updated_at":"2026-03-16T15:54:57.000Z","published_at":"2014-09-03T12:24:10.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\u003eYou're given a row vector of monotonically increasing integers most of which are consecutive. Find the upper and lower bounds of each run in that vector and return that as a row vector of intervals.\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: this is the inverse 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.mathworks.com/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eproblem 2528 - Expand intervals\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":2528,"title":"expand intervals","description":"You're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.","description_html":"\u003cp\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.\u003c/p\u003e","function_template":"function elements = ExpandIntervals(bounds)\r\n  elements = -Inf:Inf;\r\nend","test_suite":"%%\r\nbounds = [1 5 7 9 24 32];\r\nelements = [1 2 3 4 5 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [9 9 11 11];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [100 200 300 400];\r\nelements = [100:200 300:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:10; -10:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":165,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-08-25T07:54:09.000Z","updated_at":"2026-02-16T09:30:57.000Z","published_at":"2014-08-25T07:54: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\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, within these intervals.\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":2476,"title":"Max Change in Consecutive Elements","description":"If an array is given as input then find the index of consecutive elements that represent maximum change.\r\n\r\nExample:\r\n\r\n Input    x = [1 10 3 0 2 4 0 -8 9 1]\r\n\r\n Output   y = [8 9]","description_html":"\u003cp\u003eIf an array is given as input then find the index of consecutive elements that represent maximum change.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input    x = [1 10 3 0 2 4 0 -8 9 1]\u003c/pre\u003e\u003cpre\u003e Output   y = [8 9]\u003c/pre\u003e","function_template":"function y = maxChange(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 10 3 0 2 4 0 -8 9 1];\r\ny_correct = [8 9];\r\nassert(isequal(maxChange(x),y_correct))\r\n\r\n%%\r\nx = [10 15 2 18 40];\r\ny_correct = [4 5];\r\nassert(isequal(maxChange(x),y_correct))\r\n\r\n%%\r\nx = 1:10;\r\nx(4) = 0;\r\ny_correct = [4 5];\r\nassert(isequal(maxChange(x),y_correct))\r\n\r\n%%\r\nx = [1 10 100 1e3 1e4 1e5 1e6 1e7];\r\ny_correct = [7 8];\r\nassert(isequal(maxChange(x),y_correct))\r\n\r\n%%\r\nx = [-10 10 -8 7 -5 3 -2 1 -1 0];\r\ny_correct = [1 2];\r\nassert(isequal(maxChange(x),y_correct))\r\n\r\n%%\r\nx = ones(1,1e6);\r\nx(789) = 0; x(788) = 0.5;\r\ny_correct = [789 790];\r\nassert(isequal(maxChange(x),y_correct))","published":true,"deleted":false,"likes_count":3,"comments_count":6,"created_by":16361,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":181,"test_suite_updated_at":"2017-03-15T17:18:53.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-07-31T15:37:30.000Z","updated_at":"2026-02-26T20:58:45.000Z","published_at":"2014-07-31T15:38:23.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\u003eIf an array is given as input then find the index of consecutive elements that represent maximum change.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input    x = [1 10 3 0 2 4 0 -8 9 1]\\n\\n Output   y = [8 9]]]\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":2456,"title":"remove single elements","description":"Given a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\r\nExample:\r\nInput: vec = [2 2 1 2 3 4 1 2];\r\nOutput: [2 2 1 2 1 2];\r\nLoops are not allowed.","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: 153.867px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 76.9333px; transform-origin: 407px 76.9333px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42px; 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 21px; text-align: left; transform-origin: 384px 21px; 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: 378px 8px; transform-origin: 378px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\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: 28.5px 8px; transform-origin: 28.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: 40.8667px; 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 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 124px 8.5px; tab-size: 4; transform-origin: 124px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eInput: vec = [2 2 1 2 3 4 1 2];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; 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; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; 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: 88px 8.5px; tab-size: 4; transform-origin: 88px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eOutput: [2 2 1 2 1 2];\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: 71.5px 8px; transform-origin: 71.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eLoops are not allowed.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function[ans]=removeSingle(v)\r\n\r\n\r\nend","test_suite":"%%\r\n\r\nvec = [2 2 1 2 3 4 1 2];\r\nout = [2     2     1     2     1     2];\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n%%\r\nvec = ones(1,10000);\r\nout = vec;\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n\r\n%%\r\nvec = [];\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = [1 2 3 4 5];\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = primes(10);\r\nassert(isempty(removeSingle(vec)))\r\n\r\n%%\r\nvec = [4 4 5 5 1 1 2 2];\r\nout = vec;\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n\r\n%%\r\nvec = [4 1 4];\r\nout = [4 4];\r\nassert(isequal(removeSingle(vec),out))\r\n\r\n%%\r\nfiletext = fileread('removeSingle.m');\r\nillegal = contains(filetext, 'for ') || contains(filetext, 'while '); \r\nassert(~illegal)","published":true,"deleted":false,"likes_count":3,"comments_count":4,"created_by":17203,"edited_by":223089,"edited_at":"2022-10-22T18:43:22.000Z","deleted_by":null,"deleted_at":null,"solvers_count":131,"test_suite_updated_at":"2022-10-22T18:43:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-07-20T15:07:45.000Z","updated_at":"2026-03-04T04:36:47.000Z","published_at":"2014-07-20T15:07:45.000Z","restored_at":null,"restored_by":null,"spam":null,"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 a vector of integers, remove the elements that have appeared only once. The output elements should be in exact order as the input except the single elements being removed.\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[Input: vec = [2 2 1 2 3 4 1 2];\\nOutput: [2 2 1 2 1 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLoops are not allowed.\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":2235,"title":"Back to basics - mean of corner elements of a matrix","description":"Calculate the mean of corner elements of a matrix.\r\n\r\ne.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\r\n\r\nMean = (1+3+7+9)/4 = 5","description_html":"\u003cp\u003eCalculate the mean of corner elements of a matrix.\u003c/p\u003e\u003cp\u003ee.g. a=[1 2 3;\r\n        4 5 6;\r\n        7 8 9;]\u003c/p\u003e\u003cp\u003eMean = (1+3+7+9)/4 = 5\u003c/p\u003e","function_template":"function y = MeanCorner(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3; 4 5 6; 7 8 9]\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = magic(4)\r\ny_correct = 8.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = eye(4)\r\ny_correct = 0.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n%%\r\nx = repmat(5, 4,4);\r\ny_correct = 5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n%%\r\nx = [1:10];\r\ny_correct = 5.5;\r\nassert(isequal(MeanCorner(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":462,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-03-04T20:59:30.000Z","updated_at":"2026-02-26T15:47:13.000Z","published_at":"2014-03-04T21:00:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eCalculate the mean of corner elements of a matrix.\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\u003ee.g. a=[1 2 3; 4 5 6; 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\u003eMean = (1+3+7+9)/4 = 5\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":2228,"title":"Time Expansion ","description":"How can you slow down any discrete-time signal?\r\n\r\nExample\r\n\r\nInput original signal x.\r\n\r\n x = [1 2 3 -1 -2 -5 -4] \r\n\r\nWe want to slow down n=3 times original signal. Output signal must be like y.\r\n\r\n y = [1 0 0 2 0 0 3 0 0 -1 0 0 -2 0 0 -5 0 0 -4]\r\n","description_html":"\u003cp\u003eHow can you slow down any discrete-time signal?\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cp\u003eInput original signal x.\u003c/p\u003e\u003cpre\u003e x = [1 2 3 -1 -2 -5 -4] \u003c/pre\u003e\u003cp\u003eWe want to slow down n=3 times original signal. Output signal must be like y.\u003c/p\u003e\u003cpre\u003e y = [1 0 0 2 0 0 3 0 0 -1 0 0 -2 0 0 -5 0 0 -4]\u003c/pre\u003e","function_template":"function y= time_expansion(x,n)\r\ny=x;n;\r\nend","test_suite":"%%\r\nn=4\r\nx=[2 1 2 3 4 5 -3 4 -1 2 2 2]\r\ny_correct = [2 0 0 0 1 0 0 0 2 0 0 0 3 0 0 0 4 0 0 0 5 0 0 0 -3 0 0 0 4 0 0 0 -1 0 0 0 2 0 0 0 2 0 0 0 2];\r\nassert(isequal(time_expansion(x,n),y_correct))\r\n%%\r\nn=1\r\nx=[2 1 2 3 4 5 -3 4 -1 2 2 2]\r\ny_correct=x;\r\nassert(isequal(time_expansion(x,n),y_correct))\r\n%%\r\nn=5\r\nx=[2 1 2 3 4]\r\ny_correct=[2 0 0 0 0 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 4];\r\nassert(isequal(time_expansion(x,n),y_correct))\r\n%%\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":186,"test_suite_updated_at":"2014-03-02T12:59:19.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-03-02T12:48:45.000Z","updated_at":"2026-03-16T15:57:26.000Z","published_at":"2014-03-02T12:59:19.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\u003eHow can you slow down any discrete-time signal?\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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput original signal x.\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 -1 -2 -5 -4]]]\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\u003eWe want to slow down n=3 times original signal. Output signal must be like y.\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[ y = [1 0 0 2 0 0 3 0 0 -1 0 0 -2 0 0 -5 0 0 -4]]]\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":2225,"title":"Three...is a magic number.","description":"Yes it is...\r\n\r\nIt's a magic number...\r\n\r\nTo help you get rid of that earworm, here's a new Cody problem.  You are given a square matrix containing positive integers.  We want to determine if there are three consecutive occurrences of the same number in a row or column.  For example:\r\n\r\n 1 1 1\r\n 4 2 3\r\n 2 3 4\r\n\r\nShould be marked \"true\" because there are three consecutive ones in the first row.  Likewise\r\n\r\n 5 2 3\r\n 5 3 2\r\n 5 4 1\r\n\r\nshould also be marked \"true\" because there are three consecutive fives in the first column.  However:\r\n\r\n 5 2 3\r\n 3 5 2\r\n 1 4 5\r\n\r\nIs false, as we do not care about the three consecutive fives along the trace of the matrix.  The matrix will always be at least 3x3, but they can be larger.  Good luck!\r\n","description_html":"\u003cp\u003eYes it is...\u003c/p\u003e\u003cp\u003eIt's a magic number...\u003c/p\u003e\u003cp\u003eTo help you get rid of that earworm, here's a new Cody problem.  You are given a square matrix containing positive integers.  We want to determine if there are three consecutive occurrences of the same number in a row or column.  For example:\u003c/p\u003e\u003cpre\u003e 1 1 1\r\n 4 2 3\r\n 2 3 4\u003c/pre\u003e\u003cp\u003eShould be marked \"true\" because there are three consecutive ones in the first row.  Likewise\u003c/p\u003e\u003cpre\u003e 5 2 3\r\n 5 3 2\r\n 5 4 1\u003c/pre\u003e\u003cp\u003eshould also be marked \"true\" because there are three consecutive fives in the first column.  However:\u003c/p\u003e\u003cpre\u003e 5 2 3\r\n 3 5 2\r\n 1 4 5\u003c/pre\u003e\u003cp\u003eIs false, as we do not care about the three consecutive fives along the trace of the matrix.  The matrix will always be at least 3x3, but they can be larger.  Good luck!\u003c/p\u003e","function_template":"function y = match_three(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx=[  1     2     7     6     7     2     7     7 ;\r\n     7     7     5     3     5     3     2     5 ;\r\n     1     6     5     4     3     5     7     5 ;\r\n     6     6     7     4     6     3     7     1 ;\r\n     4     2     4     2     2     5     5     6 ;\r\n     2     4     4     7     4     4     2     7 ;\r\n     7     4     2     3     6     4     7     1 ;\r\n     4     6     4     2     5     5     1     4];\r\ny_correct = 0;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=mod(magic(4),4);\r\ny_correct = 0;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=mod(magic(7),2);\r\ny_correct = 1;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[5 2 3 ; 5 3 2 ; 5 4 1] ;\r\ny_correct = 1;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[  3     3     4     2     1     3     1\r\n     5     4     3     1     6     1     5\r\n     3     6     1     2     3     1     5\r\n     3     3     2     5     6     3     1\r\n     3     6     5     3     1     5     6\r\n     4     2     4     2     4     3     3\r\n     2     6     5     1     5     1     4];\r\ny_correct = 1;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[ 1 1 1 ; 4 2 3 ; 2 3 4];\r\ny_correct = 1;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[ 1 2 3 ; 4 5 6 ; 7 8 9];\r\ny_correct = 0;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[ 1 1 1 1 ; 2 4 6 8 ; 3 6 9 12 ; 4 8 12 16];\r\ny_correct = 1;\r\nassert(isequal(match_three(x),y_correct))\r\n%%\r\nx=[ 1 5 7 9 ; 1 5 7 9 ; 2 4 6 8 ; 1 5 7 9];\r\ny_correct = 0;\r\nassert(isequal(match_three(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":106,"test_suite_updated_at":"2014-10-24T12:48:36.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-02-28T17:16:58.000Z","updated_at":"2026-03-04T04:50:19.000Z","published_at":"2014-02-28T17:42:01.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\u003eYes it is...\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\u003eIt's a magic number...\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 help you get rid of that earworm, here's a new Cody problem. You are given a square matrix containing positive integers. We want to determine if there are three consecutive occurrences of the same number in a row or column. For 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[ 1 1 1\\n 4 2 3\\n 2 3 4]]\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 be marked \\\"true\\\" because there are three consecutive ones in the first row. Likewise\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[ 5 2 3\\n 5 3 2\\n 5 4 1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eshould also be marked \\\"true\\\" because there are three consecutive fives in the first column. However:\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[ 5 2 3\\n 3 5 2\\n 1 4 5]]\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\u003eIs false, as we do not care about the three consecutive fives along the trace of the matrix. The matrix will always be at least 3x3, but they can be larger. Good luck!\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":2200,"title":"counting groups!","description":"This problem is about counting groups. \r\n\r\nExample\r\n\r\nIf you have x:\r\n\r\n x = [0.8 0.8 0.8 0.3 0.3 0.4 0.5 0.6 0.6 0.9]\r\n\r\nthen all 0.8's being first in line, get a value of 1, all 0.3's get a value of 2, all 0.4's a value of 3 and so on, till the output y is:\r\n\r\n y = [1 1 1 2 2 3 4 5 5 6]\r\n\r\nThat's it!\r\n\r\nPlease note, to make it easier, the list will be \"pre-sorted\".","description_html":"\u003cp\u003eThis problem is about counting groups.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cp\u003eIf you have x:\u003c/p\u003e\u003cpre\u003e x = [0.8 0.8 0.8 0.3 0.3 0.4 0.5 0.6 0.6 0.9]\u003c/pre\u003e\u003cp\u003ethen all 0.8's being first in line, get a value of 1, all 0.3's get a value of 2, all 0.4's a value of 3 and so on, till the output y is:\u003c/p\u003e\u003cpre\u003e y = [1 1 1 2 2 3 4 5 5 6]\u003c/pre\u003e\u003cp\u003eThat's it!\u003c/p\u003e\u003cp\u003ePlease note, to make it easier, the list will be \"pre-sorted\".\u003c/p\u003e","function_template":"function y = GroupSort(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [0.8 0.8 0.8 0.3 0.3 0.4 0.5 0.6 0.6 0.9];\r\ny_correct = [1 1 1 2 2 3 4 5 5 6];\r\nassert(isequal(GroupSort(x),y_correct))\r\n%%\r\nx = [2 2 2 5 5 1 1 9 9 8 6 3 3];\r\ny_correct = [1 1 1 2 2 3 3 4 4 5 6 7 7];\r\nassert(isequal(GroupSort(x),y_correct))\r\n%%\r\nx = [1 2 3];\r\ny_correct = [1 2 3];\r\nassert(isequal(GroupSort(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":155,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-02-19T00:58:50.000Z","updated_at":"2026-02-26T21:40:23.000Z","published_at":"2014-02-19T00:59:34.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\u003eThis problem is about counting groups.\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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf you have x:\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 = [0.8 0.8 0.8 0.3 0.3 0.4 0.5 0.6 0.6 0.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\u003ethen all 0.8's being first in line, get a value of 1, all 0.3's get a value of 2, all 0.4's a value of 3 and so on, till the output y 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[ y = [1 1 1 2 2 3 4 5 5 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\u003eThat's it!\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\u003ePlease note, to make it easier, the list will be \\\"pre-sorted\\\".\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":2158,"title":"Largest territory","description":"Determine whose territory is largest. If there are multiple numbers tied for the largest territory, return the smallest number. \r\n\r\nFor example,\r\n\r\n X = \r\n [ 1 1 2 2\r\n   1 1 2 2\r\n   2 2 2 2 ]\r\n\r\n y = 2","description_html":"\u003cp\u003eDetermine whose territory is largest. If there are multiple numbers tied for the largest territory, return the smallest number.\u003c/p\u003e\u003cp\u003eFor example,\u003c/p\u003e\u003cpre\u003e X = \r\n [ 1 1 2 2\r\n   1 1 2 2\r\n   2 2 2 2 ]\u003c/pre\u003e\u003cpre\u003e y = 2\u003c/pre\u003e","function_template":"function y = largest_territory(X)\r\n  y = 0;\r\nend","test_suite":"%%\r\nX = [1 0 -1];\r\ny_correct = -1;\r\nassert(isequal(largest_territory(X),y_correct));\r\n\r\n%%\r\nX = [1 1 1 2 2];\r\ny_correct = 1;\r\nassert(isequal(largest_territory(X),y_correct));\r\n\r\n%%\r\nX = [1 1 1 2 3; 1 1 1 2 3; 1 1 1 2 3; 1 1 2 2 2; 2 2 2 2 2];\r\ny_correct = 1;\r\nassert(isequal(largest_territory(X),y_correct));\r\n\r\n%%\r\nX = [1 1 1 1 1 1 1; 1 1 2 2 2 1 1; 1 1 2 2 2 1 1; 1 1 2 2 2 1 1; 1 1 2 2 1 1 1; 1 1 1 1 1 1 1; 3 3 3 3 3 3 3];\r\ny_correct = 1;\r\nassert(isequal(largest_territory(X),y_correct));\r\n\r\n%%\r\nX = [1:100; 101:150, 51:100; 101:175, 76:100; 101:190, 91:100];\r\ny_correct = 91;\r\nassert(isequal(largest_territory(X),y_correct));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":22720,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":110,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-02-06T11:53:22.000Z","updated_at":"2026-02-16T09:46:54.000Z","published_at":"2014-02-06T12:18:56.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\u003eDetermine whose territory is largest. If there are multiple numbers tied for the largest territory, return the smallest number.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example,\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 = \\n [ 1 1 2 2\\n   1 1 2 2\\n   2 2 2 2 ]\\n\\n y = 2]]\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":2153,"title":"Replace pattern 0 1 0 and 1 0 1","description":"Find and replace a pattern in a row of zeroes and ones.\r\n\r\n* Find 1 0 1 and replace it with 1 1 1\r\n* Find 0 1 0 and replace it with 0 0 0 \r\n\r\nExample:\r\n\r\n Input : [ 1 1 1 0 1 1 0 0 0 1 0 0 0 ]\r\n Output: [ 1 1 1 1 1 1 0 0 0 0 0 0 0 ]\r\n\r\n","description_html":"\u003cp\u003eFind and replace a pattern in a row of zeroes and ones.\u003c/p\u003e\u003cul\u003e\u003cli\u003eFind 1 0 1 and replace it with 1 1 1\u003c/li\u003e\u003cli\u003eFind 0 1 0 and replace it with 0 0 0\u003c/li\u003e\u003c/ul\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input : [ 1 1 1 0 1 1 0 0 0 1 0 0 0 ]\r\n Output: [ 1 1 1 1 1 1 0 0 0 0 0 0 0 ]\u003c/pre\u003e","function_template":"function y = replace_pattern(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =         [1 0 1 1 0 0 1 0 0 1 1 1 1 0 0 0];\r\ny_correct = [1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0];\r\nassert(isequal(replace_pattern(x),y_correct))\r\n\r\n%%\r\nx =         [0 1 1 1 0 1 1 0 0 1 1 0 0 1 0 0 1 0 0 1];\r\ny_correct = [0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0 1];\r\nassert(isequal(replace_pattern(x),y_correct))\r\n\r\n%%\r\nx = [ones(1,10); ones(1,10); zeros(1,10)];\r\nx = x(:)';\r\ny_correct = [ones(1,29) 0];\r\nassert(isequal(replace_pattern(x),y_correct))\r\n\r\n%%\r\nx =         [1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 0 0 1 0 0 1 0 0 0 1];\r\ny_correct = [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1];\r\nassert(isequal(replace_pattern(x),y_correct))\r\n\r\n%%\r\nx = [ones(1,250) zeros(1,250), ones(1,250) zeros(1,250)];\r\ny_correct = x;\r\nx([3,35,67,100,103,201]) = 0;\r\nx([257,301,333,404]) = 1;\r\nx([505,606,616]) = 0;\r\nx(997) = 1;\r\nassert(isequal(replace_pattern(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":22350,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":159,"test_suite_updated_at":"2017-03-15T17:02:55.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-02-05T18:36:21.000Z","updated_at":"2026-02-16T09:48:44.000Z","published_at":"2014-02-05T18:46:30.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\u003eFind and replace a pattern in a row of zeroes and ones.\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\u003eFind 1 0 1 and replace it with 1 1 1\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\u003eFind 0 1 0 and replace it with 0 0 0\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input : [ 1 1 1 0 1 1 0 0 0 1 0 0 0 ]\\n Output: [ 1 1 1 1 1 1 0 0 0 0 0 0 0 ]]]\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":2145,"title":"Find the index of n in magic(n)","description":"If input n=5, then magic(n) is\r\n\r\n    17    24     1     8    15\r\n    23     5     7    14    16\r\n     4     6    13    20    22\r\n    10    12    19    21     3\r\n    11    18    25     2     9\r\n\r\nThe output is of the form [row,column] for the place where n appears.\r\n\r\n output = [2,2]\r\n","description_html":"\u003cp\u003eIf input n=5, then magic(n) is\u003c/p\u003e\u003cpre\u003e    17    24     1     8    15\r\n    23     5     7    14    16\r\n     4     6    13    20    22\r\n    10    12    19    21     3\r\n    11    18    25     2     9\u003c/pre\u003e\u003cp\u003eThe output is of the form [row,column] for the place where n appears.\u003c/p\u003e\u003cpre\u003e output = [2,2]\u003c/pre\u003e","function_template":"function y = nim(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 7;\r\ny_correct = [2,3];\r\nassert(isequal(nim(x),y_correct))\r\n%%\r\nx = 11;\r\ny_correct = [2,5];\r\nassert(isequal(nim(x),y_correct))\r\n%%\r\nx = 3;\r\ny_correct = [2,1];\r\nassert(isequal(nim(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":1,"created_by":1690,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":273,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-01-31T07:51:37.000Z","updated_at":"2026-04-01T20:58:17.000Z","published_at":"2014-01-31T07:51:37.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\u003eIf input n=5, then magic(n) 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[    17    24     1     8    15\\n    23     5     7    14    16\\n     4     6    13    20    22\\n    10    12    19    21     3\\n    11    18    25     2     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 output is of the form [row,column] for the place where n appears.\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[ output = [2,2]]]\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":2129,"title":"Sum of odd numbers in a matrix","description":"Find the sum of all the odd numbers in a matrix.\r\n\r\nExample\r\n\r\n x = [2 3 5 7 1 4 11]\r\n y = 27","description_html":"\u003cp\u003eFind the sum of all the odd numbers in a matrix.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x = [2 3 5 7 1 4 11]\r\n y = 27\u003c/pre\u003e","function_template":"function y = oddsum(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(oddsum(x),y_correct))\r\n\r\n%%\r\nx = [2 3 5 7 1 4];\r\ny_correct = 16;\r\nassert(isequal(oddsum(x),y_correct))\r\n\r\n%%\r\nx = [2 3 5 7 1 4;9 1 5 8 3 2];\r\ny_correct = 34;\r\nassert(isequal(oddsum(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":1690,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":618,"test_suite_updated_at":"2014-01-27T16:15:12.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-01-23T01:41:10.000Z","updated_at":"2026-03-18T23:41:13.000Z","published_at":"2014-01-23T01:41:10.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\u003eFind the sum of all the odd numbers in a matrix.\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[ x = [2 3 5 7 1 4 11]\\n y = 27]]\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":2091,"title":"return row and column indices given 2 values which define a range","description":"Inspired by problem http://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\r\nA little complication: let your function be able to deal with a random order of the input arguments.\r\nIf all input arguments have the same size, assume that the first argument is the \"matrix\" with value(s).\r\nDon't use \"find\" and don't use \"regexp\".","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: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 76.5px; transform-origin: 407px 76.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 63px; 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 31.5px; text-align: left; transform-origin: 384px 31.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: 62px 8px; transform-origin: 62px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInspired by problem\u003c/span\u003e\u003c/span\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e \u003c/span\u003e\u003c/span\u003e\u003ca target='_blank' href = \"/#null\"\u003e\u003cspan style=\"\"\u003e\u003cspan style=\"\"\u003ehttp://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice\u003c/span\u003e\u003c/span\u003e\u003c/a\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: 2px 8px; transform-origin: 2px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\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: 303.5px 8px; transform-origin: 303.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA little complication: let your function be able to deal with a random order of the input arguments.\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: 316px 8px; transform-origin: 316px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf all input arguments have the same size, assume that the first argument is the \"matrix\" with value(s).\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: 124px 8px; transform-origin: 124px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eDon't use \"find\" and don't use \"regexp\".\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function [rowidx,colidx] = RCMatrixIndices(x1,x2,x3)\r\n  A=1;\r\nuplim=1;\r\nlowlim=1;\r\nend","test_suite":"%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R1,C1]=RCMatrixIndices(x1,x2,x3);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R1,fr1),isequal(C1,fc1)))\r\n%%\r\nfiletext = fileread('RCMatrixIndices.m');\r\nassert(isempty(strfind(filetext, 'find'))\u0026isempty(strfind(filetext, 'regexp'))...\r\n    \u0026isempty(strfind(filetext, 'str2num')))\r\n%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R2,C2]=RCMatrixIndices(x2,x1, x3);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R2,fr1),isequal(C2,fc1)))\r\n%%\r\nx1=magic(5);\r\nx2=3;\r\nx3=9;\r\n[R3,C3]=RCMatrixIndices(x1,x3,x2);\r\n[fr1,fc1]=find(and(x1\u003e=x2,x1\u003cx3));\r\nassert(and(isequal(R3,fr1),isequal(C3,fc1)))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=3;\r\nuplim=9;\r\n[R4,C4]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(length(A(4*(C4-1)+R4))==16)\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=4;\r\nuplim=9;\r\n%extract only 8\r\n[R5,C5]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(all(A(4*(C5-1)+R5)==8))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=4;\r\nuplim=7;\r\n[R6,C6]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(isempty(R6),isempty(C6)))\r\n%%\r\nA=...\r\n[3 3 3 3;...\r\n 8 3 3 3;...\r\n 8 8 3 3;...\r\n 8 8 8 3];\r\nlowlim=2;\r\nuplim=7;\r\n[R7,C7]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(all(A(4*(C7-1)+R7)==3),length(R7==10)))\r\n%%\r\nA=1;\r\nlowlim=1;\r\nuplim=1;\r\n[R8,C8]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(isempty(R8),isempty(C8)))\r\n%%\r\nA=1;\r\nlowlim=1;\r\nuplim=2;\r\n[R9,C9]=RCMatrixIndices(A,uplim,lowlim);\r\nassert(and(R9==1,C9==1))","published":true,"deleted":false,"likes_count":3,"comments_count":7,"created_by":20079,"edited_by":223089,"edited_at":"2022-11-21T11:00:01.000Z","deleted_by":null,"deleted_at":null,"solvers_count":78,"test_suite_updated_at":"2022-11-21T11:00:01.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2014-01-07T08:32:32.000Z","updated_at":"2026-03-09T19:07:20.000Z","published_at":"2014-01-07T12:29:47.000Z","restored_at":null,"restored_by":null,"spam":null,"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\u003eInspired by 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=\\\"\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://www.mathworks.co.kr/matlabcentral/cody/problems/856-getting-the-indices-from-a-matrice\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e Inputs: - matrix A, lower limit, upper limit Ouputs: - indices of matrix elements which are bigger than or equal to lower limit and smaller than upper limit\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\u003eA little complication: let your function be able to deal with a random order of the input arguments.\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\u003eIf all input arguments have the same size, assume that the first argument is the \\\"matrix\\\" with value(s).\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\u003eDon't use \\\"find\\\" and don't use \\\"regexp\\\".\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":1986,"title":"Another colon problem","description":"This is simple problem based on problems 555, 801, 1118, etc.\r\n\r\nCreate an index vector from two input vectors.\r\n\r\nExample:\r\n\r\n  input: [1 8 12] [4 5 9]\r\n output: [1 2 3 4 8 7 6 5 12 11 10 9]","description_html":"\u003cp\u003eThis is simple problem based on problems 555, 801, 1118, etc.\u003c/p\u003e\u003cp\u003eCreate an index vector from two input vectors.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003einput: [1 8 12] [4 5 9]\r\noutput: [1 2 3 4 8 7 6 5 12 11 10 9]\r\n\u003c/pre\u003e","function_template":"function out = another(in1,in2)\r\n  out=in1:in2;\r\nend","test_suite":"%%\r\nassert(isequal(another([1 8 12],[4 5 9]),[1 2 3 4 8 7 6 5 12 11 10 9]))\r\n%%\r\nassert(isequal(another([5 5 5],[9 5 1]),[5 6 7 8 9 5 5 4 3 2 1]))\r\n%%\r\nassert(isequal(another([100 102],[-1 105]),[100:-1:-1 102 103 104 105]))\r\n%%\r\ny=[randi(20) randi([30 40],1,2) randi(3)];\r\nassert(isequal(another(y(1:2:3),y(2:2:4)),[y(1):y(2) y(3):-1:y(4)]))\r\n%%\r\nassert(isequal(another([1 2 1 2 2 2 1 1 1],[1 2 1 1 2 1 2 2 1]),[1 2 1 2 1 2 2 1 1 2 1 2 1]))","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":166,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2013-11-13T12:47:02.000Z","updated_at":"2026-02-16T09:53:03.000Z","published_at":"2013-11-13T12:50:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is simple problem based on problems 555, 801, 1118, etc.\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\u003eCreate an index vector from two input vectors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[input: [1 8 12] [4 5 9]\\noutput: [1 2 3 4 8 7 6 5 12 11 10 9]]]\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":1985,"title":"How unique?","description":"Sometimes, when we check unique entries of vector we would like to know how many times each value occurs.\r\n\r\nGiven vector of numbers *A* return vector *U* of unique values of A and corresponding vector *H* with occurrences.\r\n\r\nExample:\r\n\r\n   in:  A = [2 2 2 3 3 2 3 8 6 5 6]\r\n  out:  U = [2 3 8 6 5]\r\n        H = [4 3 1 2 1]  ","description_html":"\u003cp\u003eSometimes, when we check unique entries of vector we would like to know how many times each value occurs.\u003c/p\u003e\u003cp\u003eGiven vector of numbers \u003cb\u003eA\u003c/b\u003e return vector \u003cb\u003eU\u003c/b\u003e of unique values of A and corresponding vector \u003cb\u003eH\u003c/b\u003e with occurrences.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e   in:  A = [2 2 2 3 3 2 3 8 6 5 6]\r\n  out:  U = [2 3 8 6 5]\r\n        H = [4 3 1 2 1]  \u003c/pre\u003e","function_template":"function [U,H] = hunique(A)\r\n  U = 1:5;\r\n  H = ones(1,5);\r\nend","test_suite":"%%\r\nA = [2 2 2 3 3 2 3 8 6 5 6];\r\n[U, H] = hunique(A);\r\nU_ok = [2 3 8 6 5];\r\nH_ok = [4 3 1 2 1];\r\nassert(isequal(U,U_ok));\r\nassert(isequal(H,H_ok));\r\n%%\r\nA = [2 2 2 3 3 2 3 8 6 5 6 8];\r\n[U, H] = hunique(A);\r\nU_ok = [2 3 8 6 5];\r\nH_ok = [4 3 2 2 1];\r\nassert(isequal(U,U_ok));\r\nassert(isequal(H,H_ok));\r\n%%\r\nA = 100:-11:1;\r\nassert(isequal(hunique(A),A));\r\n[~,H] = hunique(A);\r\nassert(isequal(H,ones(1,10)));\r\n%%\r\nA = randi([-10 10],1,100);\r\n[U,H] = hunique(A);\r\nassert(sum(H)==numel(A));\r\nassert(isequal(unique(A),sort(U)));\r\n\r\n% number of test cases may increace in the future.\r\n% any proposals of test cases warmly welcome.","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":137,"test_suite_updated_at":"2014-04-06T18:52:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-11-12T23:00:10.000Z","updated_at":"2026-02-26T16:00:10.000Z","published_at":"2013-11-13T23:40:01.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\u003eSometimes, when we check unique entries of vector we would like to know how many times each value occurs.\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 vector of numbers\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 return vector\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\u003eU\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of unique values of A and corresponding vector\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\u003eH\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e with occurrences.\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[   in:  A = [2 2 2 3 3 2 3 8 6 5 6]\\n  out:  U = [2 3 8 6 5]\\n        H = [4 3 1 2 1]]]\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":1961,"title":"Finding neighbors of [-1:1] in a matrix....","description":"Hello All!\r\n\r\nWell I found this one fun to figure out, all you have to do is make a matrix of 1's or 0's (true or false) that show whether or not a number in a matrix is sitting directly next to (a neighbor) that is number that is +1 or -1 or == to that of the original number.  Here are some examples:\r\n\r\n  M1 = [1 2 1;\r\n        5 6 7;\r\n        2 3 6]\r\n  \r\nSO now find numbers next to one another that are +1 of each-other.\r\n  \r\n  output = [1 1 1;\r\n            1 1 1;\r\n            1 1 1]\r\nOne more:\r\n  \r\n  M2 = [8 8 8;\r\n        4 4 4;\r\n        1 9 7]\r\n  \r\nSO now find numbers next to one another that are +1 of each-other.\r\n  \r\n  output = [1 1 1;\r\n            1 1 1;\r\n            0 0 0]\r\n  \r\nOne more:\r\n  \r\n  M3 = [1  8   5;\r\n        4  10  22;\r\n        1  66  7]\r\n  \r\nSO now find numbers next to one another that are +1 of each-other.\r\n  \r\n  output = [0 0 0;\r\n            0 0 0;\r\n            0 0 0]\r\n\r\nWell good luck!\r\n\r\n\r\n\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eHello All!\u003c/p\u003e\u003cp\u003eWell I found this one fun to figure out, all you have to do is make a matrix of 1's or 0's (true or false) that show whether or not a number in a matrix is sitting directly next to (a neighbor) that is number that is +1 or -1 or == to that of the original number.  Here are some examples:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM1 = [1 2 1;\r\n      5 6 7;\r\n      2 3 6]\r\n\u003c/pre\u003e\u003cp\u003eSO now find numbers next to one another that are +1 of each-other.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eoutput = [1 1 1;\r\n          1 1 1;\r\n          1 1 1]\r\nOne more:\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003eM2 = [8 8 8;\r\n      4 4 4;\r\n      1 9 7]\r\n\u003c/pre\u003e\u003cp\u003eSO now find numbers next to one another that are +1 of each-other.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eoutput = [1 1 1;\r\n          1 1 1;\r\n          0 0 0]\r\n\u003c/pre\u003e\u003cp\u003eOne more:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM3 = [1  8   5;\r\n      4  10  22;\r\n      1  66  7]\r\n\u003c/pre\u003e\u003cp\u003eSO now find numbers next to one another that are +1 of each-other.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eoutput = [0 0 0;\r\n          0 0 0;\r\n          0 0 0]\r\n\u003c/pre\u003e\u003cp\u003eWell good luck!\u003c/p\u003e","function_template":"function output = neighbors(x)\r\n  output = x;\r\nend","test_suite":"%%\r\nx = [1 2 1;\r\n     5 6 7;\r\n     2 3 6];\r\noutput = [1 1 1;\r\n          1 1 1;\r\n          1 1 1]\r\nassert(isequal(neighbors(x),output))\r\n%%\r\nx = [8 8 8;\r\n     4 4 4;\r\n     1 9 7]\r\noutput = [1 1 1;\r\n          1 1 1;\r\n          0 0 0]\r\nassert(isequal(neighbors(x),output))\r\n%%\r\nx = [1  8   5;\r\n     4  10  22;\r\n     1  66  7]\r\noutput = [0 0 0;\r\n          0 0 0;\r\n          0 0 0]\r\nassert(isequal(neighbors(x),output))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":15013,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":86,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2013-10-27T16:27:57.000Z","updated_at":"2026-02-27T13:46:09.000Z","published_at":"2013-10-27T16:27:57.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\u003eHello All!\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\u003eWell I found this one fun to figure out, all you have to do is make a matrix of 1's or 0's (true or false) that show whether or not a number in a matrix is sitting directly next to (a neighbor) that is number that is +1 or -1 or == to that of the original number. Here are some examples:\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[M1 = [1 2 1;\\n      5 6 7;\\n      2 3 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\u003eSO now find numbers next to one another that are +1 of each-other.\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[output = [1 1 1;\\n          1 1 1;\\n          1 1 1]\\nOne more:\\n\\nM2 = [8 8 8;\\n      4 4 4;\\n      1 9 7]]]\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\u003eSO now find numbers next to one another that are +1 of each-other.\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[output = [1 1 1;\\n          1 1 1;\\n          0 0 0]]]\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\u003eOne more:\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[M3 = [1  8   5;\\n      4  10  22;\\n      1  66  7]]]\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\u003eSO now find numbers next to one another that are +1 of each-other.\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[output = [0 0 0;\\n          0 0 0;\\n          0 0 0]]]\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\u003eWell good luck!\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":1923,"title":"Find the maximum two numbers of every column of a matrix","description":"Find the maximum two numbers of every column of a matrix.\r\n\r\nExample:\r\n\r\nIf we input a matrix \r\n\r\n A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\r\n\r\nwe should get\r\n\r\n B = [ 6 2 5\r\n       4 1 4 ]\r\n","description_html":"\u003cp\u003eFind the maximum two numbers of every column of a matrix.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eIf we input a matrix\u003c/p\u003e\u003cpre\u003e A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\u003c/pre\u003e\u003cp\u003ewe should get\u003c/p\u003e\u003cpre\u003e B = [ 6 2 5\r\n       4 1 4 ]\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4;\r\n     6 0 3;\r\n     4 1 5];\r\ny_correct = [6 2 5;\r\n             4 1 4];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = ones(3);\r\ny_correct = ones(2,3);\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = [ones(1,4); zeros(1,4)];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1:5;\r\n     6:10;\r\n     11:15;\r\n     16:20;\r\n     21:25];\r\ny_correct = [21:25; 16:20];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 5 7 3 47 2  3;\r\n     6 7 1 5 23 1 47;\r\n     7 1 3 2 68 4 11];\r\ny_correct = [7 7 7 5 68 4 47;\r\n             6 5 3 3 47 2 11];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":231,"test_suite_updated_at":"2017-03-15T16:43:08.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-10-08T14:30:23.000Z","updated_at":"2026-03-31T17:07:39.000Z","published_at":"2013-10-08T14:30:22.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\u003eFind the maximum two numbers of every column of a matrix.\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=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we input a 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[ A = [ 1 2 4\\n       6 0 3\\n       4 1 5 ]]]\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\u003ewe should get\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[ B = [ 6 2 5\\n       4 1 4 ]]]\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":1896,"title":"Index one element in each vector of an array along a given dimension","description":"Functions like min and max can return in their second output argument the index of the element in each vector along a particular dimension which meets the particular criterion being requested. E.g.\r\n\r\n   A = rand(3);\r\n   [B, I] = min(A, [], 2);\r\n\r\nWrite a function which, given an array A, and an index array I (like the one created above), can reconstruct the first output of functions like min and max. E.g.\r\n\r\n   C = dimsel(A, I);\r\n\r\nsuch that C is equal to B.","description_html":"\u003cp\u003eFunctions like min and max can return in their second output argument the index of the element in each vector along a particular dimension which meets the particular criterion being requested. E.g.\u003c/p\u003e\u003cpre\u003e   A = rand(3);\r\n   [B, I] = min(A, [], 2);\u003c/pre\u003e\u003cp\u003eWrite a function which, given an array A, and an index array I (like the one created above), can reconstruct the first output of functions like min and max. E.g.\u003c/p\u003e\u003cpre\u003e   C = dimsel(A, I);\u003c/pre\u003e\u003cp\u003esuch that C is equal to B.\u003c/p\u003e","function_template":"function B = dimsel(A, I)\r\n  B = A;\r\nend","test_suite":"%%\r\nfor a = 1:30\r\nndms = ceil(rand(1) * 5) + 1\r\nsz = 1 + ceil(rand(1, ndms) * 10);\r\nA = rand(sz);\r\nsz1 = sz(1);\r\nsz(1) = 1;\r\nI = ceil(rand(sz) * sz1);\r\nB = reshape(A(I(:)+(0:sz1:numel(A)-1)'), size(I));\r\np = randperm(ndms);\r\nA = permute(A, p);\r\nI = permute(I, p);\r\nB = permute(B, p);\r\nassert(isequal(dimsel(A, I), B));\r\nend","published":true,"deleted":false,"likes_count":10,"comments_count":14,"created_by":135,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":57,"test_suite_updated_at":"2018-07-31T17:31:50.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-09-26T14:00:01.000Z","updated_at":"2026-03-17T19:17:17.000Z","published_at":"2013-09-26T14:00:08.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\u003eFunctions like min and max can return in their second output argument the index of the element in each vector along a particular dimension which meets the particular criterion being requested. E.g.\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 = rand(3);\\n   [B, I] = min(A, [], 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\u003eWrite a function which, given an array A, and an index array I (like the one created above), can reconstruct the first output of functions like min and max. E.g.\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 = dimsel(A, I);]]\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\u003esuch that C is equal to B.\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":1812,"title":"Tridiagonal","description":"Return an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\r\n\r\nExample \r\n\r\n a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\r\n","description_html":"\u003cp\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e a=1\r\n b=2\r\n c=3\r\n n=5\r\n T =  [2     3     0     0     0;\r\n       1     2     3     0     0;\r\n       0     1     2     3     0;\r\n       0     0     1     2     3;\r\n       0     0     0     1     2]\u003c/pre\u003e","function_template":"function T = tridiag(a, b, c, n)\r\n  \r\nend","test_suite":"%%\r\na = 1;\r\nb = 2;\r\nc = 3;\r\nn = 5;\r\ny_correct = [ 2     3     0     0     0;\r\n              1     2     3     0     0;\r\n              0     1     2     3     0;\r\n              0     0     1     2     3;\r\n              0     0     0     1     2];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 9;\r\nb = 5;\r\nc = -17;\r\nn = 3;\r\ny_correct = [ 5   -17     0 ;\r\n              9     5   -17 ;\r\n              0     9     5 ];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 4;\r\nb = -1;\r\nc = 8;\r\nn = 4;\r\ny_correct = [-1     8     0     0;\r\n              4    -1     8     0;\r\n              0     4    -1     8;\r\n              0     0     4    -1];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))\r\n\r\n%%\r\na = 11;\r\nb = 21;\r\nc = 30;\r\nn = 5;\r\ny_correct = [21    30     0     0     0;\r\n             11    21    30     0     0;\r\n              0    11    21    30     0;\r\n              0     0    11    21    30;\r\n              0     0     0    11    21];\r\nassert(isequal(tridiag(a, b, c, n),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":5,"created_by":14639,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":173,"test_suite_updated_at":"2017-03-15T16:29:22.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-08-14T09:35:02.000Z","updated_at":"2026-02-27T15:40:54.000Z","published_at":"2013-08-14T09:35:02.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\u003eReturn an n-by-n matrix that has a, b, c as the subdiagonal, main diagonal, and superdiagonal entries in the matrix.\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=1\\n b=2\\n c=3\\n n=5\\n T =  [2     3     0     0     0;\\n       1     2     3     0     0;\\n       0     1     2     3     0;\\n       0     0     1     2     3;\\n       0     0     0     1     2]]]\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":1471,"title":"Index of a Rational number","description":"The set of real numbers are infinite. They are so many that real numbers can't even be enumerated. However, unlike real numbers the set of integers is countably infinite as a mapping from 1,2,3,4,5 .... to 0,1,-1,2,-2,3,-3 can be made easily. \r\n\r\nSurprisingly, rational Numbers are countably infinite too !!, meaning they can be enumerated. A diagonalization argument introduced by George Cantor easily shows this. Recollect that rational numbers are those numbers that can be represented in the form p/q. \u003chttp://en.wikipedia.org/wiki/Rational_numbers\u003e\r\n\r\nex: The first ten rational numbers under this enumeration are 1/1, 2/1, 1/2, 3/1, 2/2, 1/3, 4/1, 3/2, 2/3, 1/4. \r\n\r\n\r\nFind the index of a positive rational number enumerated this way.\r\nie the index of 1/3 is 6\r\n\r\nProblem 1) \r\nNext: \u003chttp://www.mathworks.com/matlabcentral/cody/problems/1472 1472\u003e","description_html":"\u003cp\u003eThe set of real numbers are infinite. They are so many that real numbers can't even be enumerated. However, unlike real numbers the set of integers is countably infinite as a mapping from 1,2,3,4,5 .... to 0,1,-1,2,-2,3,-3 can be made easily.\u003c/p\u003e\u003cp\u003eSurprisingly, rational Numbers are countably infinite too !!, meaning they can be enumerated. A diagonalization argument introduced by George Cantor easily shows this. Recollect that rational numbers are those numbers that can be represented in the form p/q. \u003ca href = \"http://en.wikipedia.org/wiki/Rational_numbers\"\u003ehttp://en.wikipedia.org/wiki/Rational_numbers\u003c/a\u003e\u003c/p\u003e\u003cp\u003eex: The first ten rational numbers under this enumeration are 1/1, 2/1, 1/2, 3/1, 2/2, 1/3, 4/1, 3/2, 2/3, 1/4.\u003c/p\u003e\u003cp\u003eFind the index of a positive rational number enumerated this way.\r\nie the index of 1/3 is 6\u003c/p\u003e\u003cp\u003eProblem 1) \r\nNext: \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/1472\"\u003e1472\u003c/a\u003e\u003c/p\u003e","function_template":"function [k] = cantor_rational2index(p,q)\r\nk=1;\r\nend","test_suite":"%%\r\np=1; q=3; \r\ny_correct = 6;\r\nassert(isequal(cantor_rational2index(p,q),y_correct))\r\n\r\n%%\r\np=2; q=3; \r\ny_correct = 9;\r\nassert(isequal(cantor_rational2index(p,q),y_correct))\r\n\r\n%%\r\np=22; q=7; \r\ny_correct = 385;\r\nassert(isequal(cantor_rational2index(p,q),y_correct))\r\n\r\n%%\r\np=355; q=113; \r\ny_correct = 108924;\r\nassert(isequal(cantor_rational2index(p,q),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":11275,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":119,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2013-04-30T01:19:49.000Z","updated_at":"2026-03-17T19:08:38.000Z","published_at":"2013-04-30T01:19: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\u003eThe set of real numbers are infinite. They are so many that real numbers can't even be enumerated. However, unlike real numbers the set of integers is countably infinite as a mapping from 1,2,3,4,5 .... to 0,1,-1,2,-2,3,-3 can be made easily.\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\u003eSurprisingly, rational Numbers are countably infinite too !!, meaning they can be enumerated. A diagonalization argument introduced by George Cantor easily shows this. Recollect that rational numbers are those numbers that can be represented in the form p/q.\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://en.wikipedia.org/wiki/Rational_numbers\\\"\u003e\u003cw:r\u003e\u003cw:t\u003ehttp://en.wikipedia.org/wiki/Rational_numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eex: The first ten rational numbers under this enumeration are 1/1, 2/1, 1/2, 3/1, 2/2, 1/3, 4/1, 3/2, 2/3, 1/4.\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 index of a positive rational number enumerated this way. ie the index of 1/3 is 6\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\u003eProblem 1) Next:\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/1472\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1472\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":574,"title":"Sort numbers by outside digits","description":"Sort the array so that they are sorted as if their value was a 5 digit number made from the first three and last two digits of the value, irrespective of the middle digits. \r\n\r\nFor example: the array is: [166552, 12389245, 88234, 74123245], it the return would be sorted as if the numbers were [16652, 12345, 88234, 74145], and therefore the return array would be: [12389245, 166552, 74123245, 88234].\r\n\r\nThe numbers are all integers \u003e= 10000, with no leading 0's. ","description_html":"\u003cp\u003eSort the array so that they are sorted as if their value was a 5 digit number made from the first three and last two digits of the value, irrespective of the middle digits.\u003c/p\u003e\u003cp\u003eFor example: the array is: [166552, 12389245, 88234, 74123245], it the return would be sorted as if the numbers were [16652, 12345, 88234, 74145], and therefore the return array would be: [12389245, 166552, 74123245, 88234].\u003c/p\u003e\u003cp\u003eThe numbers are all integers \u003e= 10000, with no leading 0's.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [12368933, 12345931, 68221, 533111, 3819999999999];\r\ny_correct = [12345931, 12368933, 3819999999999, 533111, 68221];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [4591023, 37410101, 97516, 888123, 15061789];\r\ny_correct = [15061789, 37410101, 4591023, 888123, 97516];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1110098, 1110197, 1110296, 1110395, 1110494, 1110593, 1110691];\r\ny_correct = fliplr(x);\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [324651, 65432114, 1032464, 21465476, 1232165746561, 12321];\r\ny_correct = [1032464, 12321, 1232165746561, 21465476, 324651, 65432114];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":29,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":161,"test_suite_updated_at":"2017-03-15T16:20:14.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2012-04-12T12:43:10.000Z","updated_at":"2026-02-27T16:13:49.000Z","published_at":"2012-04-12T12:44:56.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\u003eSort the array so that they are sorted as if their value was a 5 digit number made from the first three and last two digits of the value, irrespective of the middle 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: the array is: [166552, 12389245, 88234, 74123245], it the return would be sorted as if the numbers were [16652, 12345, 88234, 74145], and therefore the return array would be: [12389245, 166552, 74123245, 88234].\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 numbers are all integers \u003e= 10000, with no leading 0's.\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\"}]}"}],"no_progress_badge":{"id":53,"name":"Unknown","symbol":"unknown","description":"Partially completed groups","description_html":null,"image_location":"/images/responsive/supporting/matlabcentral/cody/badges/problem_groups_unknown_2.png","bonus":null,"players_count":0,"active":false,"created_by":null,"updated_by":null,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"created_at":"2018-01-10T23:20:29.000Z","updated_at":"2018-01-10T23:20:29.000Z","community_badge_id":null,"award_multiples":false}}