{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2025-12-14T01:33:56.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2025-12-14T00:00:00.000Z","image_id":null,"published":true,"community_created":false,"status_id":2,"is_default_group_for_player":false,"deleted_by":null,"deleted_at":null,"restored_by":null,"restored_at":null,"description_opc":null,"description_html":null,"published_at":null},"problems":[{"id":42675,"title":"Get all corner elements from a matrix where dimension of matrix is always equal to or greater than 2.","description":"if a given matrix a  = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]","description_html":"\u003cp\u003eif a given matrix a  = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 1;1 1];\r\ny_correct = [1 1;1 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [1 2 3;4 5 6];\r\ny_correct = [1 3;4 6];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [1 2 3 4;1 1 1 1;0 0 0 0;5 6 7 8];\r\ny_correct = [1 4;5 8];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":104,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-30T13:31:12.000Z","updated_at":"2026-02-15T08:52:10.000Z","published_at":"2015-10-30T13:39: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\",\"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\u003eif a given matrix a = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]\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":59546,"title":"Getting values from a vector","description":"This exercise is for finding the values that meet your criteria.\r\na = [-5 28 7 83 73];\r\nb = 23 ;\r\nc = (a \u003e b)\r\nThen :\r\nc = \r\n   0   1   0   1   1\r\nWhat we are looking for now is how to get the values :\r\ny =     \r\n    28    83    73\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 287.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 143.525px; transform-origin: 407px 143.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis exercise is for finding the values that meet your criteria.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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 30.65px; transform-origin: 404px 30.6562px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ea = [-5 28 7 83 73];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eb = 23 ;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ec = (a \u0026gt; b)\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThen :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.875px; 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.4375px; transform-origin: 404px 20.4375px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ec = \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   0   1   0   1   1\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWhat we are looking for now is how to get the values :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.875px; 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.4375px; transform-origin: 404px 20.4375px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey =     \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    28    83    73\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  \r\nend","test_suite":"%%\r\nx = [17 85 -20 99];\r\ny_correct = [85 99];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [-5 28 7 83 73];\r\ny_correct = [28 83 73];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [55 0 7 53];\r\ny_correct = [55 53];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [80 0 -90];\r\ny_correct = [80];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [10 14 -80 30 -95];\r\ny_correct = [30];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":4033021,"edited_by":4033021,"edited_at":"2024-01-10T06:33:06.000Z","deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":"2024-01-10T06:33:06.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-01-09T17:51:26.000Z","updated_at":"2026-04-02T13:30:37.000Z","published_at":"2024-01-09T18:04:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis exercise is for finding the values that meet your criteria.\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 = [-5 28 7 83 73];\\nb = 23 ;\\nc = (a \u003e b)]]\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\u003eThen :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = \\n   0   1   0   1   1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat we are looking for now is how to get the values :\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 =     \\n    28    83    73]]\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42678,"title":"For a given linear index as input for n sized square matrix, find corresponding row and column.","description":"If input is 1, the row and column will be 1 and 1 respectively.","description_html":"\u003cp\u003eIf input is 1, the row and column will be 1 and 1 respectively.\u003c/p\u003e","function_template":"function rc = your_fcn_name(i,n)\r\n  % i is index and n is length of matrix \r\nend","test_suite":"%%\r\ni = 1;n = 1;\r\ny_correct = [1,1];\r\nassert(isequal(your_fcn_name(i,n),y_correct))\r\n%%\r\ni = 7;n = 3;\r\ny_correct = [1,3];\r\nassert(isequal([your_fcn_name(i,n)],y_correct))\r\n%%\r\ni = 16;n = 7;\r\ny_correct = [2,3];\r\nassert(isequal([your_fcn_name(i,n)],y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":"2015-10-31T18:52:14.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-10-31T16:23:03.000Z","updated_at":"2026-02-06T09:45:23.000Z","published_at":"2015-10-31T16:38: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\",\"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\u003eIf input is 1, the row and column will be 1 and 1 respectively.\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":2121,"title":"Find offset of given matrix element from first matrix element","description":"Given matrix m and an element of that matrix, return the offset from its first element.\r\ne.g. m=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51\r\nThen, offset = 5\r\n\r\nReturn 0, if that element if not a matrix element","description_html":"\u003cp\u003eGiven matrix m and an element of that matrix, return the offset from its first element.\r\ne.g. m=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51\r\nThen, offset = 5\u003c/p\u003e\u003cp\u003eReturn 0, if that element if not a matrix element\u003c/p\u003e","function_template":"function offset= FindOffset(m, element)\r\n  y = x;\r\nend","test_suite":"%%\r\nm=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51;\r\noffset = 5;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=reshape([1:10],5,2);\r\nelement = 9;\r\noffset = 9;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=eye(7);\r\nelement = 0;\r\noffset = 2;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=[10 20 30 40; 50 60 70 80;];\r\nelement = 56;\r\noffset = 0;\r\nassert(isequal(FindOffset(m,element),offset));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":85,"test_suite_updated_at":"2014-01-15T19:28:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-01-15T19:21:32.000Z","updated_at":"2026-02-28T08:07:23.000Z","published_at":"2014-01-15T19:21:46.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix m and an element of that matrix, return the offset from its first element. e.g. m=[11 2 34; 40 51 6; 87 8 109] element = 51 Then, offset = 5\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\u003eReturn 0, if that element if not a matrix element\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":44326,"title":"Replace 0 indices in array with 1's","description":"Take a incoming vector, and replace 0's with ones","description_html":"\u003cp\u003eTake a incoming vector, and replace 0's with ones\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = ...;\r\nend","test_suite":"%%\r\nx = -1:1:3\r\ny_correct = [-1 1 1 2 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:22:35.000Z","updated_at":"2026-02-09T17:09:04.000Z","published_at":"2017-09-14T17:22:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eTake a incoming vector, and replace 0's with ones\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":43655,"title":"Where is the number that you want to find?","description":"For a given matrix A, find where the input number x appears.\r\nDo this task by returning the vector which contains the row and the column as its element \r\n\r\nExample\r\n\r\n A = [1 5 6 7]\r\n x = 7\r\n\r\n output = [1 4]\r\n\r\n","description_html":"\u003cp\u003eFor a given matrix A, find where the input number x appears.\r\nDo this task by returning the vector which contains the row and the column as its element\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e A = [1 5 6 7]\r\n x = 7\u003c/pre\u003e\u003cpre\u003e output = [1 4]\u003c/pre\u003e","function_template":"function y = indexmynum(A,x)\r\n\r\nend","test_suite":"%%\r\nA=magic(4)\r\nx=1\r\ny_correct = [4 4]\r\nassert(isequal(indexmynum(A,x),y_correct))\r\n%%\r\nA=magic(6)\r\nx=22\r\ny_correct = [3 4]\r\nassert(isequal(indexmynum(A,x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":88437,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2016-11-14T05:34:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-11-14T05:26:20.000Z","updated_at":"2026-02-13T16:34:31.000Z","published_at":"2016-11-14T05:26:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a given matrix A, find where the input number x appears. Do this task by returning the vector which contains the row and the column as its element\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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 5 6 7]\\n x = 7\\n\\n output = [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":47118,"title":"find the index of a number","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 111px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 55.5px; transform-origin: 407px 55.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven a number  and  a single digit number as the input.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFind the index of  that single digit number. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003efor eg. a=83456,  x=4\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eoutput should be y=3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(a,x)\r\n  y = x;\r\nend","test_suite":"%%\r\na=1234;\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=82356;\r\nx = 5;\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=1231;\r\nx = 1;\r\ny_correct = [1,4];\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=76454;\r\nx = 4;\r\ny_correct = [3,5];\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":628208,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":50,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-10-29T02:30:31.000Z","updated_at":"2026-02-13T18:28:19.000Z","published_at":"2020-10-29T02:48:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number  and  a single digit number as the input.\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\u003eFind the index of  that single digit 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efor eg. a=83456,  x=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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput should be y=3\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":44242,"title":"Replace Nan!","description":"Replace Nan in the given vector(v) with 9999.","description_html":"\u003cp\u003eReplace Nan in the given vector(v) with 9999.\u003c/p\u003e","function_template":"function y = ReplaceNan(v)\r\n  y = v;\r\nend","test_suite":"%%\r\nx=[1 2 3 0/0 4];\r\ny_correct = [1 2 3 9999 4];\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n\r\n%%\r\nx=[5:9];\r\ny_correct =[5:9];\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n\r\n%%\r\nx=repmat(0/0,1,10);\r\ny_correct = repmat(9999,1,10);\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":102298,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-06-27T13:30:08.000Z","updated_at":"2026-02-13T18:08:24.000Z","published_at":"2017-06-27T13:33:17.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\u003eReplace Nan in the given vector(v) with 9999.\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":57570,"title":" An array is given that contains the marks. Find out the highest 3 marks ","description":" An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\r\nFor example if x=[12 5 12.5 10 13 14 8]\r\nOutput will be y=[14 13 12.5]","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 102.017px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.989px 51.0085px; transform-origin: 406.996px 51.0085px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.017px; 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: 383.991px 21.0085px; text-align: left; transform-origin: 383.999px 21.0085px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor example if x=[12 5 12.5 10 13 14 8]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput will be y=[14 13 12.5]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [ 9, 6, 7, 6.5, 8, 9.5, 8, 9.5, 8, 8.5, 6, 7, 9];\r\ny_correct = [9.5,9, 8.5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [ 93, 97, 67,84,91,81,56,67,55,67,45,98,56,55,44,44,44,91,78];\r\ny_correct = [98,97, 93];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":2294940,"edited_by":2294940,"edited_at":"2023-01-20T10:16:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-18T17:47:08.000Z","updated_at":"2026-02-11T14:59:28.000Z","published_at":"2023-01-18T17:47:15.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\u003e An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\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 if x=[12 5 12.5 10 13 14 8]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput will be y=[14 13 12.5]\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":57585,"title":"Given a matrix X, manipulate it accordingly ","description":"Given a matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same column. For example \r\n➢ Input: x= [2,5; 3,8]\r\n➢ Output: y= [2,5,7; 3,8,11;5,13,18]","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 102.017px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.989px 51.0085px; transform-origin: 406.996px 51.0085px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.017px; 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: 383.991px 21.0085px; text-align: left; transform-origin: 383.999px 21.0085px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven a matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same column. For example \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e➢ Input: x= [2,5; 3,8]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e➢ Output: y= [2,5,7; 3,8,11;5,13,18]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx= [2,5; 3,8];\r\ny_correct = [2,5,7; 3,8,11;5,13,18]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=magic(6);\r\ny_correct=[35     1     6    26    19    24   111;3    32     7    21    23    25   111;31     9     2    22    27    20   111;8    28    33    17    10    15   111;30     5    34    12    14    16   111;4    36    29    13    18    11   111;111   111   111   111   111   111   666];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx= [1,2,3; 4,5,6;7,8,9]\r\ny_correct = [1, 2, 3, 6; 4, 5, 6, 15; 7, 8, 9, 24;\r\n12,15,18,45]\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2294940,"edited_by":2294940,"edited_at":"2023-01-20T10:15:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-20T10:12:56.000Z","updated_at":"2026-02-06T16:02:03.000Z","published_at":"2023-01-20T10:12:56.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 matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same 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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e➢ Input: x= [2,5; 3,8]\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\u003e➢ Output: y= [2,5,7; 3,8,11;5,13,18]\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":2092,"title":"Find offset of an element of a multi dimensional matrix","description":"For a given multi dimensional matrix and given element, find its offset from the 1st element. \r\n\r\nReturn 0, if element is not found in the matrix. \r\n\r\nIf the element is repeated in the matrix, then return the offset of its first occurrence in the matrix. \r\n\r\nE.g. \r\nM(:,:,1) = [1 2 3; 4 5 6]\r\nM(:,:,2) = [10 20 30; 40 50 60]\r\n\r\nElement is 50, then its offset = 10\r\n\r\n","description_html":"\u003cp\u003eFor a given multi dimensional matrix and given element, find its offset from the 1st element.\u003c/p\u003e\u003cp\u003eReturn 0, if element is not found in the matrix.\u003c/p\u003e\u003cp\u003eIf the element is repeated in the matrix, then return the offset of its first occurrence in the matrix.\u003c/p\u003e\u003cp\u003eE.g. \r\nM(:,:,1) = [1 2 3; 4 5 6]\r\nM(:,:,2) = [10 20 30; 40 50 60]\u003c/p\u003e\u003cp\u003eElement is 50, then its offset = 10\u003c/p\u003e","function_template":"function offset = FindOffset(matrix, element)\r\n  offset = 0;\r\nend","test_suite":"%%\r\nclear all;\r\nM(:,:,1) = [1 2 3; 4 5 6];\r\nM(:,:,2) = [10 20 30; 40 50 60];\r\nElement = 50;\r\ny_correct = 10;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 2 3; 4 5 6];\r\nM(:,:,2) = [10 20 30; 40 50 60];\r\nM(:,:,3) = [100 200 300; 400 500 600];\r\n\r\nElement = 6;\r\ny_correct = 6;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 0 0; 0 1 0]\r\nM(:,:,2) = [1 0 1; 1 1 0]\r\nM(:,:,3) = [1 1 1; 0 0 0]\r\n\r\nElement = 0;\r\ny_correct = 2;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n\r\n%%\r\nclear all;\r\nM(:,:,1,1) = [10 20 350; 30 1 50]\r\nM(:,:,2,1) = [12 0 11; 13 15 60]\r\nM(:,:,1,2) = [4 5 6; 70 80 100]\r\nM(:,:,2,2) = [1000 2000 3000; 4000 5000 6000]\r\n\r\nElement = 70;\r\ny_correct = 14;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 20 30; 40 5 60]\r\nM(:,:,2) = [89 90 100; 101 135 99]\r\nM(:,:,3) = [6 19 67; 31 41 45]\r\n\r\nElement = 102;\r\ny_correct = 0;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2014-01-07T21:56:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-01-07T21:30:10.000Z","updated_at":"2026-01-04T08:31:55.000Z","published_at":"2014-01-07T21:31:46.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\u003eFor a given multi dimensional matrix and given element, find its offset from the 1st element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn 0, if element is not found 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the element is repeated in the matrix, then return the offset of its first occurrence 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eE.g. M(:,:,1) = [1 2 3; 4 5 6] M(:,:,2) = [10 20 30; 40 50 60]\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\u003eElement is 50, then its offset = 10\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":45472,"title":"Find the sum of all integers in a given matrix","description":"Finding sum of all integers in a given matrix","description_html":"\u003cp\u003eFinding sum of all integers in a given matrix\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\n\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\n\r\nx=2\r\ny_correct=2\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\n\r\nx=[1 2]\r\ny_correct=3\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":433466,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":51,"test_suite_updated_at":"2020-04-23T15:21:31.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-22T07:12:24.000Z","updated_at":"2026-02-09T16:35:55.000Z","published_at":"2020-04-22T07:12:24.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\u003eFinding sum of all integers in a given matrix\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":58563,"title":"Convert row and column subscripts to linear indices","description":"Convert 2D row and column subscripts to linear indices WITHOUT sub2ind\r\nExample:\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [3 3];\r\nind = my_sub2ind(sz, row, col)\r\nReturns:\r\nind = 1×4\r\n\r\n     4     5     6     7","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 245.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 122.531px; transform-origin: 407.5px 122.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eConvert 2D row and column subscripts to linear indices WITHOUT sub2ind\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.75px; 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: 404.5px 40.875px; transform-origin: 404.5px 40.875px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003erow = [1 2 3 1];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ecol = [2 2 2 3];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003esz = [3 3];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eind = my_sub2ind(sz, row, col)\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eReturns:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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: 404.5px 30.6562px; transform-origin: 404.5px 30.6562px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eind = 1\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     4     5     6     7\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function ind = subToLinearIdx(sz, row, col)\r\n  ind = row;\r\nend","test_suite":"%%\r\nrow = [2 1];\r\ncol = [2 2];\r\nsz = [2 2];\r\nind_correct = [4 3];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n\r\n%%\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [3 3];\r\nind_correct = [4 5 6 7];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n\r\n%%\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [4 3];\r\nind_correct = [5 6 7 9];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":3494918,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-07-17T15:13:09.000Z","updated_at":"2026-02-24T10:46:10.000Z","published_at":"2023-07-17T15:13:09.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\u003eConvert 2D row and column subscripts to linear indices WITHOUT sub2ind\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[row = [1 2 3 1];\\ncol = [2 2 2 3];\\nsz = [3 3];\\nind = my_sub2ind(sz, row, col)]]\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\u003eReturns:\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[ind = 1×4\\n\\n     4     5     6     7]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3107,"title":"Try and Catch Simple Example","description":"Try and Catch Simple Example \r\n\r\n\u003chttp://in.mathworks.com/help/matlab/ref/try.html Example\u003e \r\n\r\nVector x=[1 4 6 8 10];\r\n\r\nCreate a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x. \r\n","description_html":"\u003cp\u003eTry and Catch Simple Example\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://in.mathworks.com/help/matlab/ref/try.html\"\u003eExample\u003c/a\u003e\u003c/p\u003e\u003cp\u003eVector x=[1 4 6 8 10];\u003c/p\u003e\u003cp\u003eCreate a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x.\u003c/p\u003e","function_template":"function y = trcatch(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 4 6 8 10];\r\nn=1;\r\ny_correct = 1;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n%% \r\nfiletext = fileread('trcatch.m');\r\nassert(~isempty(strfind(filetext, 'try')),'try missing')\r\nassert(~isempty(strfind(filetext, 'catch')),'Catch missing')\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=0;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=6;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=5;\r\ny_correct = 10;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=-25;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=3;\r\ny_correct = 6;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":27760,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-03-23T09:12:50.000Z","updated_at":"2026-02-17T08:52:20.000Z","published_at":"2015-03-23T09:12:50.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\u003eTry and Catch Simple Example\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:hyperlink w:docLocation=\\\"http://in.mathworks.com/help/matlab/ref/try.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample\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\u003eVector x=[1 4 6 8 10];\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 a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x.\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":42648,"title":"Place numbers","description":"Given two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index number. \r\n\r\nexample is\r\n\r\nfirst input is [1 2 ; 3 4];\r\n\r\nsecond input is [0 3 5 7];\r\n\r\noutput will be [0 3; 5 7];\r\n\r\nsecond example is \r\n\r\nfirst input is [1 2 ; 3 4;5 6; 1 2];\r\n\r\nsecond input is [0 3 5 7 3 2];\r\n\r\noutput will be [0 3; 5 7;3 2; 0 3];\r\n\r\n","description_html":"\u003cp\u003eGiven two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index number.\u003c/p\u003e\u003cp\u003eexample is\u003c/p\u003e\u003cp\u003efirst input is [1 2 ; 3 4];\u003c/p\u003e\u003cp\u003esecond input is [0 3 5 7];\u003c/p\u003e\u003cp\u003eoutput will be [0 3; 5 7];\u003c/p\u003e\u003cp\u003esecond example is\u003c/p\u003e\u003cp\u003efirst input is [1 2 ; 3 4;5 6; 1 2];\u003c/p\u003e\u003cp\u003esecond input is [0 3 5 7 3 2];\u003c/p\u003e\u003cp\u003eoutput will be [0 3; 5 7;3 2; 0 3];\u003c/p\u003e","function_template":"function y = place_number(index,vector)\r\n  \r\nend","test_suite":"%%\r\n\r\nindex = [1 2 ; 3 4];\r\nvector=  [0 3 5 7];\r\ny_correct =[0 3; 5 7];\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 ; 3 4;5 6; 1 2];;\r\nvector=  [0 3 5 7 3 2];\r\ny_correct =[0 3; 5 7;3 2; 0 3];;\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 3; 2 1 3];\r\nvector=  [0 3 5 ];\r\ny_correct =[0 3 5 ;3 0 5];\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 3; 4 5 6; 1 2 3;4 5 6];\r\nvector=  1:6;\r\ny_correct =index;\r\nassert(isequal(place_number(index,vector),y_correct));\r\n\r\n%%\r\nindex = [1 2 1 2; 1 2 2 2; 1 2 1 1];\r\nvector=  [6 7];\r\ny_correct =index+5;\r\nassert(isequal(place_number(index,vector),y_correct));\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":47,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-04T15:41:32.000Z","updated_at":"2026-03-02T14:18:05.000Z","published_at":"2015-10-04T15:42: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eexample 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efirst input is [1 2 ; 3 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esecond input is [0 3 5 7];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput will be [0 3; 5 7];\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\u003esecond example 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efirst input is [1 2 ; 3 4;5 6; 1 2];\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\u003esecond input is [0 3 5 7 3 2];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput will be [0 3; 5 7;3 2; 0 3];\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":43607,"title":"Logical array indexing - part 1","description":"Given an array |A| of size |p x q| , return an array |Y| of the same size such that the following conditions are satisfied.\r\n\r\n(1) The non-zero elements should be greater than a given value |'n'| .\r\n\r\n(2) These non-zero entries in |Y| should have the same values as their corresponding elements in |A|\r\n\r\nFor example: Given |A = [3 4 5 6 2 4 5 6 3 6]| and |n = 4| , return |Y = [0 0 5 6 0 0 5 6 0 6]|","description_html":"\u003cp\u003eGiven an array \u003ctt\u003eA\u003c/tt\u003e of size \u003ctt\u003ep x q\u003c/tt\u003e , return an array \u003ctt\u003eY\u003c/tt\u003e of the same size such that the following conditions are satisfied.\u003c/p\u003e\u003cp\u003e(1) The non-zero elements should be greater than a given value \u003ctt\u003e'n'\u003c/tt\u003e .\u003c/p\u003e\u003cp\u003e(2) These non-zero entries in \u003ctt\u003eY\u003c/tt\u003e should have the same values as their corresponding elements in \u003ctt\u003eA\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eFor example: Given \u003ctt\u003eA = [3 4 5 6 2 4 5 6 3 6]\u003c/tt\u003e and \u003ctt\u003en = 4\u003c/tt\u003e , return \u003ctt\u003eY = [0 0 5 6 0 0 5 6 0 6]\u003c/tt\u003e\u003c/p\u003e","function_template":"function Y = find_elements(A,n)\r\n  Y = A;\r\nend","test_suite":"%%\r\nA = [3 4 5 6 2 4 5 6 3 6];\r\nn = 4;\r\ny_correct = [0 0 5 6 0 0 5 6 0 6];\r\nassert(isequal(find_elements(A,n),y_correct))\r\n\r\n\r\n%%\r\nA = [0; 6; 1; 7; 3; 5; 2; 4];\r\nn = 3;\r\ny_correct = [0; 6; 0; 7; 0; 5; 0; 4];\r\nassert(isequal(find_elements(A,n),y_correct))\r\n\r\n\r\n%%\r\nA = magic(4);\r\nn = 8;\r\ny_correct = [16 0 0 13; 0 11 10 0; 9 0 0 12; 0 14 15 0];\r\nassert(isequal(find_elements(A,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":70119,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-24T15:31:58.000Z","updated_at":"2026-03-02T14:23:54.000Z","published_at":"2016-10-24T15:31:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep x q\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , return an array\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the same size such that the following conditions are satisfied.\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\u003e(1) The non-zero elements should be greater than a given value\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'n'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2) These non-zero entries in\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should have the same values as their corresponding elements in\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: Given\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA = [3 4 5 6 2 4 5 6 3 6]\u003c/w:t\u003e\u003c/w:r\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:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , return\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY = [0 0 5 6 0 0 5 6 0 6]\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":43144,"title":"BASICS - sum part of vector","description":"Please make a function, where as input you get vector \"x\" and and vector \"c\", where in \"c\" vector you get indexes to sum.\r\nExample:\r\n\r\n  x=[-1 2 3 4 7 9]\r\n  c=[1 4 6]\r\n  y= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12","description_html":"\u003cp\u003ePlease make a function, where as input you get vector \"x\" and and vector \"c\", where in \"c\" vector you get indexes to sum.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[-1 2 3 4 7 9]\r\nc=[1 4 6]\r\ny= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12\r\n\u003c/pre\u003e","function_template":"function y = sumvec(x,c)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [-1 2 3 4 7 9];\r\nc=[1 4 6];\r\ny_correct = 12;\r\nassert(isequal(sumvec(x,c),y_correct))\r\n\r\n%%\r\nx = [-50 -24 0 4 10 14 19 18];\r\nc=[2 3 6 7];\r\ny_correct = 9;\r\nassert(isequal(sumvec(x,c),y_correct))\r\n","published":true,"deleted":false,"likes_count":26,"comments_count":0,"created_by":90955,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":358,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T09:19:54.000Z","updated_at":"2026-02-17T09:11:59.000Z","published_at":"2016-10-07T09:19:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease make a function, where as input you get vector \\\"x\\\" and and vector \\\"c\\\", where in \\\"c\\\" vector you get indexes to sum. Example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x=[-1 2 3 4 7 9]\\nc=[1 4 6]\\ny= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12]]\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":42679,"title":"Can you reshape the matrix?","description":"Given a matrix A, is it possible to reshape it into another matrix with the given number of rows?","description_html":"\u003cp\u003eGiven a matrix A, is it possible to reshape it into another matrix with the given number of rows?\u003c/p\u003e","function_template":"function y = your_fcn_name(A,row)\r\n  y = \r\nend","test_suite":"%%\r\nA = 1;row =1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 1\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 4\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 2\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4;5];row = 2\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(A,row),y_correct));","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-11-01T13:26:18.000Z","updated_at":"2026-02-17T14:55:47.000Z","published_at":"2015-11-01T13:29:15.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix A, is it possible to reshape it into another matrix with the given number of rows?\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":42982,"title":"Select every other element of a matrix","description":"Write a function called \r\n\r\n  outMat = odd_idx( myMat )\r\n\r\nthat takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.","description_html":"\u003cp\u003eWrite a function called\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eoutMat = odd_idx( myMat )\r\n\u003c/pre\u003e\u003cp\u003ethat takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.\u003c/p\u003e","function_template":"function outMat = odd_idx( myMat )\r\n  outMat = myMat;\r\nend","test_suite":"%%\r\nassert(isequal(odd_idx([1, 2, 3;4, 5, 6;7, 8, 9]),[1, 3;7, 9]))\r\n%%\r\nassert(isequal(odd_idx([16 2 3 13;5 11 10 8;9 7 6 12;4 14 15 1]),[16, 3;9, 6]))\r\n%%\r\nassert(isequal(odd_idx(1), 1))\r\n%%\r\nassert(isequal(odd_idx([1 2]), 1))\r\n%%\r\nassert(isequal(odd_idx([1; 2]), 1))\r\n%%\r\nassert(isequal(odd_idx([7 3 4 7 2 9 4 9 5 8]), [7 4 2 4 5]))\r\n%%\r\nassert(isequal(odd_idx([5;2;8;6;6;10;4;9;6;7]),[5;8;6;4;6]))\r\n%%\r\nassert(isequal(odd_idx([2 4 4 2 2 1;4 2 2 5 2 4;4 2 2 1 2 1;2 3 5 5 1 1;3 4 2 5 5 1;3 5 3 1 4 1;5 2 2 5 5 2]), [2 4 2;  4 2 2;  3 2 5;  5 2 5]))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":53,"test_suite_updated_at":"2016-09-08T14:58:19.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-09-07T22:55:16.000Z","updated_at":"2026-03-04T14:45:40.000Z","published_at":"2016-09-08T14:52:25.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\u003eWrite a function called\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[outMat = odd_idx( myMat )]]\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 takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.\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":1741,"title":"Numeric array to cell array of strings (easy)","description":"Given a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\r\n\r\nYou may assume that every element of A is an integer on the interval [1,k].\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  A = [1 2 3\r\n       2 3 1\r\n       3 1 2];\r\n  C = {'yes','no','maybe'};\r\n\r\nThen\r\n\r\n  B = {'yes'    'no'     'maybe'\r\n       'no'     'maybe'  'yes'\r\n       'maybe'  'yes'    'no'};","description_html":"\u003cp\u003eGiven a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\u003c/p\u003e\u003cp\u003eYou may assume that every element of A is an integer on the interval [1,k].\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     2 3 1\r\n     3 1 2];\r\nC = {'yes','no','maybe'};\r\n\u003c/pre\u003e\u003cp\u003eThen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eB = {'yes'    'no'     'maybe'\r\n     'no'     'maybe'  'yes'\r\n     'maybe'  'yes'    'no'};\r\n\u003c/pre\u003e","function_template":"function B = ind2str(A,C)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = [1 2 3\r\n     2 3 1\r\n     3 1 2];\r\nC = {'yes','no','maybe'};\r\nB_correct = {'yes'    'no'     'maybe'\r\n             'no'     'maybe'  'yes'\r\n             'maybe'  'yes'    'no'};\r\nassert(isequal(ind2str(A,C),B_correct))\r\n\r\n%%\r\nA = ones(20,1);\r\nC = {'apples','oranges'};\r\nassert(all(strcmp(ind2str(A,C),'apples')))\r\n\r\n%%\r\nA = randi(1000,[22,10]);\r\nC = arrayfun(@(x) num2str(x),1:1000,'uni',0);\r\nassert(isequal(A,cellfun(@(c) str2num(c),ind2str(A,C))))\r\n\r\n%%\r\nA = randi(2,[1,100]);\r\nC = {'0','1'};\r\nassert(isequal(A-1,cellfun(@(c) str2num(c),ind2str(A,C))))\r\n\r\n%%\r\nA = [2 4 4 2 2 4];\r\nC = {'foo','bar','baz','qux'};\r\nB_correct = {'bar' 'qux' 'qux' 'bar' 'bar' 'qux'};\r\nassert(isequal(ind2str(A,C),B_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":60,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-23T17:44:26.000Z","updated_at":"2026-02-27T13:58:55.000Z","published_at":"2013-07-23T17:44:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that every element of A is an integer on the interval [1,k].\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\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\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 3\\n     2 3 1\\n     3 1 2];\\nC = {'yes','no','maybe'};]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[B = {'yes'    'no'     'maybe'\\n     'no'     'maybe'  'yes'\\n     'maybe'  'yes'    'no'};]]\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":43682,"title":"Pairwise column flip","description":"Given matrix *M_in*, flip every pair of columns. So if *M_in* is\r\n\r\n 1 2 3 4\r\n 1 2 3 4\r\n\r\nthen *M_out* is\r\n\r\n 2 1 4 3\r\n 2 1 4 3\r\n\r\nNote: if *M_in* has odd number of columns, the last column should remain unchanged. So if *M_in* 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\nthen *M_out* is\r\n\r\n 24    17     8     1    15\r\n  5    23    14     7    16\r\n  6     4    20    13    22\r\n 12    10    21    19     3\r\n 18    11     2    25     9","description_html":"\u003cp\u003eGiven matrix \u003cb\u003eM_in\u003c/b\u003e, flip every pair of columns. So if \u003cb\u003eM_in\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 1 2 3 4\r\n 1 2 3 4\u003c/pre\u003e\u003cp\u003ethen \u003cb\u003eM_out\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 2 1 4 3\r\n 2 1 4 3\u003c/pre\u003e\u003cp\u003eNote: if \u003cb\u003eM_in\u003c/b\u003e has odd number of columns, the last column should remain unchanged. So if \u003cb\u003eM_in\u003c/b\u003e 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\u003ethen \u003cb\u003eM_out\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 24    17     8     1    15\r\n  5    23    14     7    16\r\n  6     4    20    13    22\r\n 12    10    21    19     3\r\n 18    11     2    25     9\u003c/pre\u003e","function_template":"function y = flip_columns(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = 1:5;\r\ny_correct = [2 1 4 3 5];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny_correct = [2 1 4 3 5];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = magic(5);\r\ny_correct = [24 17  8  1 15; ...\r\n              5 23 14  7 16; ...\r\n              6  4 20 13 22; ...\r\n             12 10 21 19  3; ...\r\n             18 11  2 25  9];\r\nassert(isequal(flip_columns(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":33176,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-11-23T20:42:15.000Z","updated_at":"2026-02-26T11:56:58.000Z","published_at":"2016-11-23T20:43:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, flip every pair of columns. So if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 1 2 3 4\\n 1 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\u003ethen\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\u003eM_out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 2 1 4 3\\n 2 1 4 3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has odd number of columns, the last column should remain unchanged. So if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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\u003ethen\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\u003eM_out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 24    17     8     1    15\\n  5    23    14     7    16\\n  6     4    20    13    22\\n 12    10    21    19     3\\n 18    11     2    25     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":56155,"title":"Return the middle element of an NxN square matrix where N is odd","description":"Let's say you are given an NxN square matrix where N is always going to be an odd number:\r\nx = [ 1 2 3\r\n      4 5 6 \r\n      7 8 9 ]\r\nYour function should return 5.\r\n\r\nEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\r\n% Input Matrix\r\nx = []\r\n% Correct answer returned by your function\r\ny = NaN","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 275.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 137.527px; transform-origin: 407px 137.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eLet's say you are given an NxN square matrix where N is always going to be an odd number:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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 30.6518px; transform-origin: 404px 30.6562px; 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.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ex = [ 1 2 3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      4 5 6 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      7 8 9 ]\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour function should return 5.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.75px; 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 40.875px; transform-origin: 404px 40.875px; 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.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); \"\u003e% Input Matrix\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ex = []\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); \"\u003e% Correct answer returned by your function\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey = NaN\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = get_middle_element(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(get_middle_element(x),y_correct))\r\n%%\r\nx = [1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15];\r\ny_correct = 8;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [1 2 3];\r\ny_correct = 2;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [1];\r\ny_correct = 1;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [];\r\ny_correct = NaN;\r\nassert(isequaln(get_middle_element(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":427930,"edited_by":427930,"edited_at":"2022-11-29T14:19:23.000Z","deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":"2022-09-30T12:35:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T12:25:43.000Z","updated_at":"2026-02-18T14:28:38.000Z","published_at":"2022-09-30T12:35:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's say you are given an NxN square matrix where N is always going to be an odd number:\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\\n      4 5 6 \\n      7 8 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function should return 5.\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\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\u003eEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\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 Matrix\\nx = []\\n% Correct answer returned by your function\\ny = NaN]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60704,"title":"Convert RGB to Grayscale","description":"Convert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\r\n*Hint: a formula exists!","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: 51px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.5px; transform-origin: 407px 25.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; 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: 236.5px 8px; transform-origin: 236.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eConvert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\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-collapse: preserve; 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: 70.0083px 8px; transform-origin: 70.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e*Hint: a formula exists!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function g = RGB_to_gray(x)\r\n  g = 0;\r\nend","test_suite":"%%\r\nx = [0,0,0];\r\ng = 0;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%assert(isequal(RGB_to_gray(x),g))\r\n%%\r\nx = [255,255,255];\r\ng = 255;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [200,220,240];\r\ng = 216.3;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [0,255,0];\r\ng = 149.7;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [0,0,255];\r\ng = 29.1;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":4585291,"edited_by":4585291,"edited_at":"2024-08-07T19:08:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2024-08-07T19:08:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-08-07T16:17:39.000Z","updated_at":"2026-02-18T14:54:19.000Z","published_at":"2024-08-07T16:17:39.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\u003eConvert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\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\u003e*Hint: a formula exists!\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":1671,"title":"Generate the Matrix!","description":"Given n, generate the following matrix:\r\n\r\n  a = [ n  n-1 n-2 ... 2 1;\r\n       n-1 n-1 n-2 ... 2 1;\r\n       n-2 n-2 n-2 ... 2 1;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        2   2   2  ... 2 1;\r\n        1   1   1  ... 1 1]\r\n\r\nGood luck!","description_html":"\u003cp\u003eGiven n, generate the following matrix:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea = [ n  n-1 n-2 ... 2 1;\r\n     n-1 n-1 n-2 ... 2 1;\r\n     n-2 n-2 n-2 ... 2 1;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      2   2   2  ... 2 1;\r\n      1   1   1  ... 1 1]\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = mat_fun(n)\r\n  y = ones(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = [2 1; 1 1];\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = [3 2 1; 2 2 1; 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 4;\r\ny_correct = [4 3 2 1; 3 3 2 1; 2 2 2 1; 1 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":14930,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T17:16:38.000Z","updated_at":"2026-03-11T08:53:15.000Z","published_at":"2013-06-21T17:23:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n, generate the following 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 = [ n  n-1 n-2 ... 2 1;\\n     n-1 n-1 n-2 ... 2 1;\\n     n-2 n-2 n-2 ... 2 1;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      2   2   2  ... 2 1;\\n      1   1   1  ... 1 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood 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":45485,"title":"Count the non-zero elements along the diagonals that are immediately next to the main diagonal","description":"Suppose, you are being told to write a matrix, *a* as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to *count only the total non-zero elements along the diagonals* *(Blue and Green mark on the attached image)* *that are immediately next to the main diagonal* *(Red mark on the attached image)* as output *b*. How will you do that?\r\n\r\nExample: a=[1 3;4 2] and b=2;\r\n\r\n\u003chttps://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003e\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eSuppose, you are being told to write a matrix, \u003cb\u003ea\u003c/b\u003e as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to \u003cb\u003ecount only the total non-zero elements along the diagonals\u003c/b\u003e \u003cb\u003e(Blue and Green mark on the attached image)\u003c/b\u003e \u003cb\u003ethat are immediately next to the main diagonal\u003c/b\u003e \u003cb\u003e(Red mark on the attached image)\u003c/b\u003e as output \u003cb\u003eb\u003c/b\u003e. How will you do that?\u003c/p\u003e\u003cp\u003eExample: a=[1 3;4 2] and b=2;\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\"\u003ehttps://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003c/a\u003e\u003c/p\u003e","function_template":"function b=CountNearestDiagonalNonZeros(a)\r\nb=a+1;\r\nend","test_suite":"%%\r\na =magic(4);\r\nb_correct = 6;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =[-1 2 0 -6;0 1 2 -15;14 7 0 i;30 -1 0 -2];\r\nb_correct = 4;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =zeros(6);\r\nb_correct = 0;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =[-4 -3 2 1;-9 0 0 1;1 5 -5 0;2 2 -1 4];\r\nb_correct =4;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":430818,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":33,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-30T10:32:25.000Z","updated_at":"2026-03-31T12:56:36.000Z","published_at":"2020-04-30T10:54:12.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\u003eSuppose, you are being told to write a matrix,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to\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\u003ecount only the total non-zero elements along the diagonals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(Blue and Green mark on the attached image)\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\u003ethat are immediately next to the main diagonal\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(Red mark on the attached image)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as output\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. How will you do that?\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: a=[1 3;4 2] and b=2;\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:hyperlink w:docLocation=\\\"https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":960,"title":"Cell Source Index","description":"Suppose that C is a cell array whose elements consist of row vectors of elements of the same type.  For example, C could be a cell vector of strings:\r\n\r\n  C = {'abc' 'd' 'ef' 'ghij'};\r\n\r\nWe can put all the elements from all the vectors of C into a single vector:\r\n\r\n  VC = [C{:}];\r\n\r\nYour task:  write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came.  For example, if C has the value given above, then this would be the correct contents for iC:\r\n\r\n  iC = [1 1 1 2 3 3 4 4 4 4];\r\n\r\n","description_html":"\u003cp\u003eSuppose that C is a cell array whose elements consist of row vectors of elements of the same type.  For example, C could be a cell vector of strings:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eC = {'abc' 'd' 'ef' 'ghij'};\r\n\u003c/pre\u003e\u003cp\u003eWe can put all the elements from all the vectors of C into a single vector:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eVC = [C{:}];\r\n\u003c/pre\u003e\u003cp\u003eYour task:  write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came.  For example, if C has the value given above, then this would be the correct contents for iC:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eiC = [1 1 1 2 3 3 4 4 4 4];\r\n\u003c/pre\u003e","function_template":"function iC = cellSourceIndex(C)\r\n  iC = [];\r\nend","test_suite":"%%\r\nC = {'abc' 'd' 'ef' 'ghij'};\r\niC = [1 1 1 2 3 3 4 4 4 4];\r\nassert(isequal(cellSourceIndex(C),iC))\r\n\r\n%%\r\nC = {[1 2 3] [] 1 [] 2};\r\niC = [1 1 1 3 5];\r\nassert(isequal(cellSourceIndex(C),iC))\r\n\r\n%%\r\nassert(isequal(cellSourceIndex(num2cell(ones(3))),1:9))\r\n\r\n%%\r\nassert(isequal(cellSourceIndex({[] [] [] 1}),4))\r\n\r\n%%\r\nassert(isempty(cellSourceIndex({})))\r\n\r\n%%\r\nC = {struct('a',{1 2},'b',[]),struct('c',{1 2}),struct('d',{5 6 7 8})};\r\niC = [1 1 2 2 3 3 3 3];\r\nassert(isequal(cellSourceIndex(C),iC))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":3117,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-09-26T18:58:02.000Z","updated_at":"2026-03-31T10:53:41.000Z","published_at":"2012-09-26T18:58: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\u003eSuppose that C is a cell array whose elements consist of row vectors of elements of the same type. For example, C could be a cell vector of strings:\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 = {'abc' 'd' 'ef' 'ghij'};]]\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 can put all the elements from all the vectors of C into a single vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[VC = [C{:}];]]\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\u003eYour task: write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came. For example, if C has the value given above, then this would be the correct contents for iC:\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[iC = [1 1 1 2 3 3 4 4 4 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":1835,"title":"Matrix to column conversion","description":"Given a matrix of any size, convert it into a column vector.\r\ne.g A=[10 20 30;\r\n       40 50 60]\r\nthen,\r\nB = [10;\r\n    40;\r\n    20;\r\n    50;\r\n    30;\r\n    60;]","description_html":"\u003cp\u003eGiven a matrix of any size, convert it into a column vector.\r\ne.g A=[10 20 30;\r\n       40 50 60]\r\nthen,\r\nB = [10;\r\n    40;\r\n    20;\r\n    50;\r\n    30;\r\n    60;]\u003c/p\u003e","function_template":"function y = Mat2Vector(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [10 20 30;40 50 60];\r\ny_correct = [10; 40;20; 50; 30; 60;]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n\r\n%%\r\nx=[-2 -4 -6; -1 -3 -5; -10 -20 0]\r\ny_correct = [-2; -1;-10; -4; -3;-20; -6;-5;0]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n\r\n%%\r\nx=[1 2 3 4 5; 6 7 8 9 10];\r\nx(:,:,2) = [10 20 30 40 50;60 70 80 90 100];\r\ny_correct = [1;6;2;7;3;8;4;9;5;10;10;60;20;70;30;80;40;90;50;100]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":372,"test_suite_updated_at":"2013-08-18T20:55:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-18T20:39:50.000Z","updated_at":"2026-02-18T14:49:11.000Z","published_at":"2013-08-18T20:40:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix of any size, convert it into a column vector. e.g A=[10 20 30; 40 50 60] then, B = [10; 40; 20; 50; 30; 60;]\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":61021,"title":"The Case of the Missing Prototype – Check the Lab’s Logbook for Suspicious Late-Night Entries","description":"After counting the fingerprints, you turn your attention to the security logbook.It records the entry hours (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, no one is allowed inside after 9 PM (21 hours).Every suspicious late-night entry could reveal a key suspect!\r\nYour task is to determine how many entries occurred during these restricted hours.\r\nGiven a numeric vector entries, return the number of times people entered the lab at or after 21.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 61.5px; transform-origin: 408px 61.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: 385px 31.5px; text-align: left; transform-origin: 385px 31.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter counting the fingerprints, you turn your attention to the security logbook.It records the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eentry hours\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eno one is allowed inside after 9 PM (21 hours)\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.Every suspicious late-night entry could reveal a key suspect!\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour task is to determine how many entries occurred during these restricted hours.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a numeric vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eentries\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, return the number of times people entered the lab at or after 21.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function count = suspiciousEntries(entries)\r\n  y = x;\r\nend","test_suite":"%%\r\nentries = [8 10 21 22 23 17 14];\r\nentries_correct = 3;\r\nassert(isequal(suspiciousEntries(entries),entries_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":4953963,"edited_at":"2025-10-20T15:46:05.000Z","deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2025-10-20T15:46:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T15:43:22.000Z","updated_at":"2026-04-03T03:47:52.000Z","published_at":"2025-10-20T15:46:05.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\u003eAfter counting the fingerprints, you turn your attention to the security logbook.It records the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eentry hours\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eno one is allowed inside after 9 PM (21 hours)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.Every suspicious late-night entry could reveal a key suspect!\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\u003eYour task is to determine how many entries occurred during these restricted hours.\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\u003eGiven a numeric vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eentries\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the number of times people entered the lab at or after 21.\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":647,"title":"Getting the absolute index from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix row and column index from a matrix\u003e, and the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexing\u003e technique but there is another way to reference specific elements in a matrix.\r\n\r\nAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Indexing into a vector\u003e is really using this kind of indexing, but it is more natural feeling.\r\n\r\nUse \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e.\r\n\r\nGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector Binary comparison\u003e to satisfy two conditions)","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\"\u003erow and column index from a matrix\u003c/a\u003e, and the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexing\u003c/a\u003e technique but there is another way to reference specific elements in a matrix.\u003c/p\u003e\u003cp\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eIndexing into a vector\u003c/a\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/p\u003e\u003cp\u003eUse \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003eBinary comparison\u003c/a\u003e to satisfy two conditions)\u003c/p\u003e","function_template":"function AI = absoluteInBetween(M, LB, UB)\r\n  AI = 1;\r\nend","test_suite":"%%\r\nM = magic(5)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))\r\n\r\n%%\r\nM = magic(10)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":257,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:39:39.000Z","updated_at":"2026-03-29T19:40:43.000Z","published_at":"2012-05-01T15:39:39.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eYou may already know how to get the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erow and column index from a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e technique but there is another way to reference specific elements 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\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column). The upper left entry is value 1, the lower right is the highest value. MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIndexing into a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is really using this kind of indexing, but it is more natural feeling.\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\u003eUse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound). (See\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/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBinary comparison\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to satisfy two conditions)\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":646,"title":"Getting the row and column location from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexes\u003e from a vector, and to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector find the location\u003e of elements in a vector.\r\n\r\nWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\r\n\r\n   [0 1 0\r\n    0 0 0]\r\n\r\nYou might want \r\n\r\n  row = 1\r\n  col = 2\r\n\r\nor \r\n\r\n   [0 1 1\r\n    1 0 0]\r\n\r\n   row = [2\r\n          1\r\n          1]\r\n\r\n   col = [1\r\n          2\r\n          3]\r\n\r\nCheck out \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e to learn to do this.\r\n\r\nGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexes\u003c/a\u003e from a vector, and to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003efind the location\u003c/a\u003e of elements in a vector.\u003c/p\u003e\u003cp\u003eWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\u003c/p\u003e\u003cpre\u003e   [0 1 0\r\n    0 0 0]\u003c/pre\u003e\u003cp\u003eYou might want\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erow = 1\r\ncol = 2\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre\u003e   [0 1 1\r\n    1 0 0]\u003c/pre\u003e\u003cpre\u003e   row = [2\r\n          1\r\n          1]\u003c/pre\u003e\u003cpre\u003e   col = [1\r\n          2\r\n          3]\u003c/pre\u003e\u003cp\u003eCheck out \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e to learn to do this.\u003c/p\u003e\u003cp\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.\u003c/p\u003e","function_template":"function out = RCgreaterThan(M, thresh)\r\n  r = 1;\r\n  c = 1;\r\n  out = [r c]; %only one output can be checked in Cody!\r\nend","test_suite":"%%\r\nM = magic(5);\r\nthresh = 4;\r\n\r\n[r,c]= find(magic(5) \u003e 4)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))\r\n\r\n%%\r\nM = magic(6);\r\nthresh = 2;\r\n\r\n[r,c]= find(magic(6) \u003e 2)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":299,"test_suite_updated_at":"2012-05-01T15:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:19:06.000Z","updated_at":"2026-03-09T20:35:23.000Z","published_at":"2012-05-01T15:24:26.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eYou may already know how to get\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/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e from a vector, and to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the location\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of elements in a vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat if you are dealing with a matrix. Often you will want the row and column location of an element, or set of elements. For instance:\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[   [0 1 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\u003eYou might want\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[row = 1\\ncol = 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\u003eor\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[   [0 1 1\\n    1 0 0]\\n\\n   row = [2\\n          1\\n          1]\\n\\n   col = [1\\n          2\\n          3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to learn to do this.\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 matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh. R and C will be combined into matrix out.\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":105,"title":"How to find the position of an element in a vector without using the find function","description":"Write a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\r\n\r\nExamples:\r\n\r\n findPosition([1 3 5 4 2], 2)\r\n posX is 5\r\n\r\n findPosition([1 5 8 6 7 6 0], 8)\r\n posX is 3","description_html":"\u003cp\u003eWrite a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e findPosition([1 3 5 4 2], 2)\r\n posX is 5\u003c/pre\u003e\u003cpre\u003e findPosition([1 5 8 6 7 6 0], 8)\r\n posX is 3\u003c/pre\u003e","function_template":"function posX = findPosition(x,y)\r\n  posX = 0;\r\nend","test_suite":"%%\r\nx = [1 3 5 4 2];\r\ny = 2\r\nposX_correct = 5;\r\nassert(isequal(findPosition(x,y),posX_correct))\r\n\r\n\r\n%%\r\nx = [1 5 8 6 7 6 0];\r\ny = 8\r\nposX_correct = 3;\r\nassert(isequal(findPosition(x,y),posX_correct))\r\n","published":true,"deleted":false,"likes_count":14,"comments_count":8,"created_by":139,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2815,"test_suite_updated_at":"2012-01-26T23:03:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T00:51:27.000Z","updated_at":"2026-04-03T07:03:22.000Z","published_at":"2012-01-26T23:18:05.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\u003eWrite a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\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\u003eExamples:\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[ findPosition([1 3 5 4 2], 2)\\n posX is 5\\n\\n findPosition([1 5 8 6 7 6 0], 8)\\n posX is 3]]\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":54705,"title":"Draw a Diamond shape in ones Matrix with '0' s","description":"Input will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\r\ny =\r\n\r\n     1     0     1\r\n     0     1     0\r\n     1     0     1\r\n\r\n\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 282px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 141px; transform-origin: 407px 141px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eInput will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ey =\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     1     0     1\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     0     1     0\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     1     0     1\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1;0 1 0;1 0 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = [1 1 0 1 1;1 0 1 0 1;0 1 1 1 0;1 0 1 0 1;1 1 0 1 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=7;\r\ny_correct = [ 1 1 1 0 1 1 1;1 1 0 1 0 1 1;1 0 1 1 1 0 1;0 1 1 1 1 1 0;1 0 1 1 1 0 1;1 1 0 1 0 1 1;1 1 1 0 1 1 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":2061009,"edited_by":2061009,"edited_at":"2022-06-04T06:51:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-06-04T06:50:43.000Z","updated_at":"2026-03-24T13:37:47.000Z","published_at":"2022-06-04T06:51:32.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\u003eInput will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\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\u003ey =\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\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\u003e     1     0     1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e     0     1     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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e     1     0     1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1951,"title":"Better Index Number ","description":"Let's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\r\n\r\n    file1\r\n    file101\r\n    file2\r\n    etc.\r\n\r\nWhich is not ideal when you want your files to go like this:\r\n\r\n    file1\r\n    file2\r\n    file101\r\n    etc.\r\n\r\nSo let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file. ","description_html":"\u003cp\u003eLet's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\u003c/p\u003e\u003cpre\u003e    file1\r\n    file101\r\n    file2\r\n    etc.\u003c/pre\u003e\u003cp\u003eWhich is not ideal when you want your files to go like this:\u003c/p\u003e\u003cpre\u003e    file1\r\n    file2\r\n    file101\r\n    etc.\u003c/pre\u003e\u003cp\u003eSo let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file.\u003c/p\u003e","function_template":"function n_str = betterIndexNum(n,max_n)\r\n  n_str = str(n);\r\nend","test_suite":"%%\r\nn = 1;\r\nmax_n = 9;\r\nn_str = '1';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 1;\r\nmax_n = 28;\r\nn_str = '01';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 28;\r\nmax_n = 848984;\r\nn_str = '000028';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 10;\r\nmax_n = 100;\r\nn_str = '010';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3743,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":"2013-10-24T06:58:01.000Z","rescore_all_solutions":false,"group_id":673,"created_at":"2013-10-20T07:52:06.000Z","updated_at":"2026-02-26T15:47:19.000Z","published_at":"2013-10-20T08:03:17.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\u003eLet's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\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[    file1\\n    file101\\n    file2\\n    etc.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhich is not ideal when you want your files to go like this:\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[    file1\\n    file2\\n    file101\\n    etc.]]\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 let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file.\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":47508,"title":"Convert sorting indices to ranks","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 93px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 46.5px; transform-origin: 407px 46.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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe second output of sort() is the sorting index vector, telling where the corresponding element in the sorted vector was in the raw vector. However sometimes we want to know where the elements of the raw vector goes into the sorted vector, i.e., ranks.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCan you find the shortest solution?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function Ranks = SortingIndices2Ranks(SortingIndices)\r\n  Ranks=SortingIndices;\r\nend","test_suite":"%%\r\nRawVector=rand(10,1);\r\n[SortedVector,SortingIndices]=sort(RawVector);\r\nRanks=SortingIndices2Ranks(SortingIndices);\r\nassert(isequal(SortedVector(Ranks),RawVector));","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":362068,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-11-15T04:05:17.000Z","updated_at":"2025-11-28T17:59:25.000Z","published_at":"2020-11-15T04:05:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second output of sort() is the sorting index vector, telling where the corresponding element in the sorted vector was in the raw vector. However sometimes we want to know where the elements of the raw vector goes into the sorted vector, i.e., ranks.\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\u003eCan you find the shortest solution?\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":1368,"title":"Create an 8-color version of an image","description":"This problem was inspired by a tweet I saw from @MATLAB regarding \u003chttp://www.mathworks.com/matlabcentral/fileexchange/37816-the-warholer?s_eid=PSM_3808 The Warholer\u003e.\r\n\r\nGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \"image\" will only have 8 colors.\r\n\r\nYou may assume that the inputs are on the interval [0,255].\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThis problem was inspired by a tweet I saw from @MATLAB regarding \u003ca href = \"http://www.mathworks.com/matlabcentral/fileexchange/37816-the-warholer?s_eid=PSM_3808\"\u003eThe Warholer\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \"image\" will only have 8 colors.\u003c/p\u003e\u003cp\u003eYou may assume that the inputs are on the interval [0,255].\u003c/p\u003e","function_template":"function B = warholer(A,t)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = randi([51 255],[600 800 3]);\r\nt = [0 25 50];\r\nB = warholer(A,t);\r\nassert(all(B(:)==255))\r\n\r\n%%\r\nA = randi(100,[800 600 3]);\r\nt = [100 255 100];\r\nB = warholer(A,t);\r\nassert(all(B(:)==0))\r\n\r\n%%\r\nA = zeros(200,200,3);\r\nt = randi(255,1,3);\r\nB = warholer(A,t);\r\nassert(all(B(:)==0))\r\n\r\n%%\r\nA = 255*ones(100,100,3);\r\nt = randi(254,1,3);\r\nB = warholer(A,t);\r\nassert(all(B(:)==255))\r\n\r\n%%\r\nA(:,:,1) = randi([0 120],[480 320]);\r\nA(:,:,2) = randi([80 200],[480 320]);\r\nA(:,:,3) = randi([160 240],[480 320]);\r\nt = [150 50 150];\r\nB = warholer(A,t);\r\nassert(all(all(B(:,:,1)==0)))\r\nassert(all(all(B(:,:,2)==255)))\r\nassert(all(all(B(:,:,3)==255)))\r\n\r\n%%\r\nA(:,:,1) = randi([0 100],[480 320]);\r\nA(:,:,2) = randi([80 180],[480 320]);\r\nA(:,:,3) = randi([100 240],[480 320]);\r\nt = [180 60 250];\r\nB = warholer(A,t);\r\nassert(all(all(B(:,:,1)==0)))\r\nassert(all(all(B(:,:,2)==255)))\r\nassert(all(all(B(:,:,3)==0)))\r\n\r\n%%\r\nA(:,:,1) = magic(5)*10;\r\nA(:,:,2) = spiral(5)*10;\r\nA(:,:,3) = toeplitz(1:5)*50;\r\nt = [159 99 149];\r\nB_correct(:,:,1) = [255 255 0   0   0;\r\n                    255 0   0   0   255;\r\n                    0   0   0   255 255;\r\n                    0   0   255 255 0;\r\n                    0   255 255 0   0];\r\nB_correct(:,:,2) = [255 255 255 255 255;\r\n                    255 0   0   0   255;\r\n                    255 0   0   0   255;\r\n                    255 0   0   0   255;\r\n                    255 255 255 255 255];\r\nB_correct(:,:,3) = [0   0   255 255 255;\r\n                    0   0   0   255 255;\r\n                    255 0   0   0   255;\r\n                    255 255 0   0   0;\r\n                    255 255 255 0   0];\r\nassert(isequal(warholer(A,t),B_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2013-08-05T02:37:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-20T23:26:39.000Z","updated_at":"2026-03-31T14:55:47.000Z","published_at":"2013-08-05T02:37:21.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 was inspired by a tweet I saw from @MATLAB regarding\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/fileexchange/37816-the-warholer?s_eid=PSM_3808\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eThe Warholer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \\\"image\\\" will only have 8 colors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that the inputs are on the interval [0,255].\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":61032,"title":"The MATLAB Treasure Hunt – Count Matching Symbols on the Ancient Scroll to Unlock the Next Clue","description":"Inside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\r\nA note beside it says: “Count those that mirror the key symbol — they guide your way.”\r\nGiven a character array or string s and a single character key, count how many times key appears in s.\r\nReturn this count as n.\r\nEach correct count reveals one rune on the treasure map!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 70.5px; transform-origin: 408px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA note beside it says: \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e“Count those that mirror the key symbol — they guide your way.”\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a character array or string \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and a single character \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ekey\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, count how many times \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ekey\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e appears in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn this count as \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003en\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEach correct count reveals one rune on the treasure map!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = countSymbols(s,key)\r\n  y = x;\r\nend","test_suite":"%%\r\ns = 'x#x@xx@#x';\r\nkey = 'x';\r\ny_correct = 5;\r\nassert(isequal(countSymbols(s,key),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-21T09:27:12.000Z","updated_at":"2026-03-10T12:41:25.000Z","published_at":"2025-10-21T09:27:12.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\u003eInside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\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 note beside it says: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e“Count those that mirror the key symbol — they guide your way.”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a character array or string \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a single character \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ekey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, count how many times \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ekey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e appears in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn this count as \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach correct count reveals one rune on the treasure map!\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":53950,"title":"Time reverse indices","description":"Time reverse the index values as follows\r\nIndexIn = [7 1 0]    \r\nIndexOut = [7 6 0]\r\nNote that the indices are zero based and sorted from largest to smallest.\r\nYou can think of this as a time reversal of a vector:\r\n[7 1 0] --\u003e [1     1     0     0     0     0     0     1 ] \r\n[7 6 0] --\u003e [1     0     0     0     0     0     1     1 ]\r\n\r\nHere is a second example\r\n[8 4 3 2 0]  --\u003e [ 1     0     1     1     1     0     0     0     1 ]\r\n[8 6 5 4 0]  --\u003e [ 1     0     0     0     1     1     1     0     1 ]\r\n\r\nBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 465px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 331.5px 232.5px; transform-origin: 331.5px 232.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eTime reverse the index values as follows\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIndexIn = [7 1 0]    \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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIndexOut = [7 6 0]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eNote that the indices are zero based and sorted from largest to smallest.\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYou can think of this as a time reversal of a vector:\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[7 1 0] --\u0026gt; [1     1     0     0     0     0     0     1 ] \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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[7 6 0] --\u0026gt; [1     0     0     0     0     0     1     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eHere is a second example\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[8 4 3 2 0]  --\u0026gt; [ 1     0     1     1     1     0     0     0     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[8 6 5 4 0]  --\u0026gt; [ 1     0     0     0     1     1     1     0     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 105px; 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: 308.5px 52.5px; text-align: left; transform-origin: 308.5px 52.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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function IndexOut = reverseIndices(IndexIn)\r\n  IndexOut = IndexIn;\r\nend","test_suite":"%%\r\nx = [7  1  0];\r\ny_correct = [7  6  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [8  4  3  2  0];\r\ny_correct = [8  6  5  4  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [9  4  0];\r\ny_correct = [9  5  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [10   3   0];\r\ny_correct = [10   7   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [11   2   0];\r\ny_correct = [11   9   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [45   4   3   1   0];\r\ny_correct = [45  44  42  41   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [46   8   5   3   2   1   0];\r\ny_correct = [46  45  44  43  41  38   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [47   5   0];\r\ny_correct = [47  42   0];\r\nassert(isequal(reverseIndices(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":280816,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-01-20T21:14:20.000Z","updated_at":"2025-07-13T09:05:06.000Z","published_at":"2022-01-20T21:14:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTime reverse the index values as follows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIndexIn = [7 1 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIndexOut = [7 6 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote that the indices are zero based and sorted from largest to smallest.\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\u003eYou can think of this as a time reversal of a vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[7 1 0] --\u0026gt; [1     1     0     0     0     0     0     1 ] \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[7 6 0] --\u0026gt; [1     0     0     0     0     0     1     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eHere is a second example\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\u003e[8 4 3 2 0]  --\u0026gt; [ 1     0     1     1     1     0     0     0     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[8 6 5 4 0]  --\u0026gt; [ 1     0     0     0     1     1     1     0     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.\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":640,"title":"Getting logical indexes","description":"This is a basic MATLAB operation.  It is for instructional purposes.\r\n\r\n---\r\n\r\nLogical indexing works like this.\r\n\r\n  thresh = 4;\r\n  vec    = [1 2 3 4 5 6 7 8];\r\n  \r\n  vi     = (vec \u003e thresh)\r\n  \r\n  vi =\r\n  \r\n       0     0     0     0     1     1     1     1\r\n\r\nOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\r\n\r\nIt can be used to get the values out:\r\n\r\n  big = vec(vi)\r\n  \r\n  big =\r\n  \r\n       5     6     7     8\r\n\r\nGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\r\n\r\nNote, this works just as well with scalars and matrices.\r\n\r\n----\r\n\r\nTo get the indices where this comparison is true, see this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Cody problem\u003e.","description_html":"\u003cp\u003eThis is a basic MATLAB operation.  It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eLogical indexing works like this.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ethresh = 4;\r\nvec    = [1 2 3 4 5 6 7 8];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi     = (vec \u003e thresh)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0     0     1     1     1     1\u003c/pre\u003e\u003cp\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/p\u003e\u003cp\u003eIt can be used to get the values out:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ebig = vec(vi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ebig =\r\n\u003c/pre\u003e\u003cpre\u003e       5     6     7     8\u003c/pre\u003e\u003cp\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/p\u003e\u003cp\u003eNote, this works just as well with scalars and matrices.\u003c/p\u003e\u003cp\u003e----\u003c/p\u003e\u003cp\u003eTo get the indices where this comparison is true, see this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eCody problem\u003c/a\u003e.\u003c/p\u003e","function_template":"function vi = binaryEqualsVector(vec, v)\r\n  vi = true;\r\nend","test_suite":"%%\r\nvec = [1 2 3 3 2 1];\r\nv = 2;\r\ny_correct = [false true false false true false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 2 3 4 5 6];\r\nv = 0;\r\ny_correct = [false false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 1 1 1 1];\r\nv = 1;\r\ny_correct = [true true true true true];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = 'abcdef';\r\nv = 'a';\r\ny_correct = [true false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1182,"test_suite_updated_at":"2012-04-30T18:48:13.000Z","rescore_all_solutions":false,"group_id":12,"created_at":"2012-04-30T18:46:03.000Z","updated_at":"2026-02-10T12:14:38.000Z","published_at":"2012-04-30T18:48:13.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eLogical indexing works like this.\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[thresh = 4;\\nvec    = [1 2 3 4 5 6 7 8];\\n\\nvi     = (vec \u003e thresh)\\n\\nvi =\\n\\n       0     0     0     0     1     1     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\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 can be used to get the values out:\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[big = vec(vi)\\n\\nbig =\\n\\n       5     6     7     8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\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 works just as well with scalars and matrices.\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\u003e----\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo get the indices where this comparison is true, see this\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/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody problem\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":1786,"title":"Create an index-powered vector","description":"Given a input vector x, return y as index-powered vector as shown below.\r\n\r\nExample\r\n\r\n x = [2 3 6 9]\r\n\r\nthen y should be \r\n\r\n [2^1 3^2 6^3 9^4] = [2 9 216 6561]\r\n","description_html":"\u003cp\u003eGiven a input vector x, return y as index-powered vector as shown below.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x = [2 3 6 9]\u003c/pre\u003e\u003cp\u003ethen y should be\u003c/p\u003e\u003cpre\u003e [2^1 3^2 6^3 9^4] = [2 9 216 6561]\u003c/pre\u003e","function_template":"function y = index_power(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2 3 6 9];\r\ny_correct = [2 9 216 6561];\r\nassert(isequal(index_power(x),y_correct))\r\n\r\n%%\r\nx = [1 5 11 0 -3 -6];\r\ny_correct = [1  25 1331 0 -243 46656];\r\nassert(isequal(index_power(x),y_correct))\r\n\r\n%%\r\nx = [0 8 -12 0 -8 -2];\r\ny_correct = [0 64 -1728 0 -32768 64];\r\nassert(isequal(index_power(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":941,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":13,"created_at":"2013-08-12T02:52:55.000Z","updated_at":"2026-03-31T02:56:27.000Z","published_at":"2013-08-12T02:54:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a input vector x, return y as index-powered vector as shown below.\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 6 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 y should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [2^1 3^2 6^3 9^4] = [2 9 216 6561]]]\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":2012,"title":"Tony's trick for duplicating an mx1 vector n times","description":"Without using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 0.\r\n\r\nExamples\r\n\r\nIf\r\n\r\n v = 5;\r\n n = 3;\r\n\r\nthen return v1:\r\n\r\n v1 = [5 5 5] \r\n\r\nIf a 2d matrix is supplied then the vector v will be the first column.\r\n\r\n V = magic(4);\r\n n = 4;\r\n\r\nthen v and v1 are returned as shown below.\r\n\r\n v = [16 5 9 4]'\r\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 4] \r\n\r\nHint: use indexing\r\n","description_html":"\u003cp\u003eWithout using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 0.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre\u003e v = 5;\r\n n = 3;\u003c/pre\u003e\u003cp\u003ethen return v1:\u003c/p\u003e\u003cpre\u003e v1 = [5 5 5] \u003c/pre\u003e\u003cp\u003eIf a 2d matrix is supplied then the vector v will be the first column.\u003c/p\u003e\u003cpre\u003e V = magic(4);\r\n n = 4;\u003c/pre\u003e\u003cp\u003ethen v and v1 are returned as shown below.\u003c/p\u003e\u003cpre\u003e v = [16 5 9 4]'\r\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 4] \u003c/pre\u003e\u003cp\u003eHint: use indexing\u003c/p\u003e","function_template":"function v1 = reproduce_nv(v,n)\r\n  v1 = v;\r\nend","test_suite":"%%\r\nx=magic(3);\r\nn=3;\r\ny_correct=[8 8 8; 3 3 3; 4 4 4];\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%%\r\nx=magic(10);\r\nn=19;\r\ny_correct=repmat(x(:,1),1,19);\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%% \r\nx=1;\r\nn=0;\r\ny_correct=linspace(x,x,n); %arbitrary way to get the soln\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%%\r\nx='1';\r\nn=7;\r\ny_correct=['1' '1' '1' '1' '1' '1' '1'];\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-11-23T08:42:47.000Z","updated_at":"2026-04-02T12:30:19.000Z","published_at":"2013-11-23T08:48:28.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\u003eWithout using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 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\u003eExamples\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\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[ v = 5;\\n n = 3;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen return v1:\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[ v1 = [5 5 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\u003eIf a 2d matrix is supplied then the vector v will be the first column.\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[ V = magic(4);\\n n = 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\u003ethen v and v1 are returned as shown below.\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[ v = [16 5 9 4]'\\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 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\u003eHint: use indexing\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":56453,"title":"Multiply each matrix element by its row index and add its column index.","description":"Return a matrix the same size as the input, multiply each element by its row index and add its column index.\r\nExample:\r\nx = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]\r\nshould return\r\ny = [ 2 4 6 ; 9 12 15; 22 26 30 ]","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: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 70.5px; transform-origin: 407px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 334.125px 7.91667px; transform-origin: 334.125px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a matrix the same size as the input, multiply each element by its row index and add its column index.\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: 29.175px 7.91667px; transform-origin: 29.175px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\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: 77.5667px 7.91667px; transform-origin: 77.5667px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]\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: 40.85px 7.91667px; transform-origin: 40.85px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eshould return\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: 95.0833px 7.91667px; transform-origin: 95.0833px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ey = [ 2 4 6 ; 9 12 15; 22 26 30 ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = MultRowAddCol(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = [ 1 2 3 ; 4 5 6 ; 7 8 9 ];\r\ny_correct = [ 2 4 6 ; 9 12 15; 22 26 30 ];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = [101:110;111:120;121:130];\r\ny_correct = [102:2:120;223:3:250;364:4:400];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = reshape(-40:2:-2,4,5);\r\nx(1) = Inf;\r\ny_correct = [Inf -30 -21 -12 -3;-75 -58 -41 -24 -7;-107 -82 -57 -32 -7;-135 -102 -69 -36 -3];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx=[];\r\nassert(isempty(MultRowAddCol(x)));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":2414210,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-11-04T18:36:47.000Z","updated_at":"2026-03-27T16:46:15.000Z","published_at":"2022-11-04T18:36: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\u003eReturn a matrix the same size as the input, multiply each element by its row index and add its column index.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = [ 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\u003eshould return\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\u003ey = [ 2 4 6 ; 9 12 15; 22 26 30 ]\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":44797,"title":"Cannibal eating odd and even numbered men","description":"There are N men in a queue.  A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time.  In the first round he eats all the odd-numbered.  In the next round he eats all even-numbered.  This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? \r\ne.g. If N = 6,\r\n\r\nMen remaining after round 1: 2, 4, 6\r\n\r\nMen remaining after round 2: 2, 6\r\n\r\nMen remaining after round 3: 6\r\n\r\nHence answer = 6\r\n","description_html":"\u003cp\u003eThere are N men in a queue.  A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time.  In the first round he eats all the odd-numbered.  In the next round he eats all even-numbered.  This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? \r\ne.g. If N = 6,\u003c/p\u003e\u003cp\u003eMen remaining after round 1: 2, 4, 6\u003c/p\u003e\u003cp\u003eMen remaining after round 2: 2, 6\u003c/p\u003e\u003cp\u003eMen remaining after round 3: 6\u003c/p\u003e\u003cp\u003eHence answer = 6\u003c/p\u003e","function_template":"function y = survivor_odds(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1000;\r\ny_correct = 342;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n%%\r\nx = 2000;\r\ny_correct = 1366;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n%%\r\nx = 10000;\r\ny_correct = 5462;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":107204,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":31,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-11-29T07:49:28.000Z","updated_at":"2025-12-07T16:57:25.000Z","published_at":"2018-11-29T07:49:32.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\u003eThere are N men in a queue. A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time. In the first round he eats all the odd-numbered. In the next round he eats all even-numbered. This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? e.g. If N = 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 1: 2, 4, 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 2: 2, 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 3: 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHence answer = 6\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":44496,"title":"vector indexes for a matrix","description":"Matlab allows us to use several indexing styles making code simpler and easier to read than using loops. \r\n\r\nVectors can have vector subscripts\r\n\r\n  V = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n     2     4     6\r\n\r\nIn case of matrices, it allows us to use linear indexing.\r\n \r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n     2     4     6\r\n\r\n\r\nGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops. \r\n\r\nFor example (tl;dr)\r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\n  P = [1 1 2]; Q = [1 3 2];\r\n  Matrix_VectorIndexes(M,P,Q)\r\n  ans =\r\n     2     4     6\r\n\r\n","description_html":"\u003cp\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\u003c/p\u003e\u003cp\u003eVectors can have vector subscripts\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eV = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eIn case of matrices, it allows us to use linear indexing.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\u003c/p\u003e\u003cp\u003eFor example (tl;dr)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 1 2]; Q = [1 3 2];\r\nMatrix_VectorIndexes(M,P,Q)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e","function_template":"function y = Matrix_VectorIndexes(M,P,Q)\r\n  y = M(P,Q);  %M(P,Q) gives wrong answer because matlab reads it as linear indexing of matrices \r\n               % M(1,1) is not considered linear indexing, but M([1,1]),M([1],[1]) etc., is \r\nend","test_suite":"%%\r\nM = [1 2 3;\r\n     4 5 6;\r\n     7 8 9];\r\nP = [1 2 3]; Q= [1 2 3];\r\ny_correct = [1,5,9];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 3 2]; Q = [1 1 2];\r\ny_correct = [2,4,6];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = 1:3; Q = 3:-1:1;\r\ny_correct = [4,9,8];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = reshape(repmat((1:3)',[1,3]),[1,9]);\r\nQ = reshape(repmat(1:3,[3,1]),[1,9]);\r\ny_correct = M(:)';\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4 2;\r\n     7 9 6 1; \r\n     8 2 3 5];\r\nP = [2,1,3,2]; Q = 1:4;\r\ny_correct = [7,5,3,1];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":162999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2018-06-16T21:47:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-10T07:13:18.000Z","updated_at":"2026-04-02T13:18:07.000Z","published_at":"2018-01-10T07:33:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\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\u003eVectors can have vector subscripts\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[V = [2 3 4 5 6 7 8 9 10];\\nidx = [1 3 5];\\nV(idx)\\nans =\\n   2     4     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\u003eIn case of matrices, it allows us to use linear indexing.\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nidx = [1 3 5];\\nM(idx) \\nans =\\n   2     4     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\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\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 (tl;dr)\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nP = [1 1 2]; Q = [1 3 2];\\nMatrix_VectorIndexes(M,P,Q)\\nans =\\n   2     4     6]]\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":44706,"title":"The Deadly Sin","description":"Melvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates.\r\nCan you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\r\n\r\nExample \r\n  \r\n\r\n  Input:\r\nx = [5 3]\r\n\r\n  \r\nExplanation:\r\nDenoting Melvyn as M, Banner as B\r\n\r\nM=5, B=3 - Banner eats 3 chocolates of Melvyn.\r\n\r\nM=2, B=3 - Melvyn eats 2 chocolates of Banner.\r\n\r\nM=2, B=1 - Banner eats 1 chocolate of Melvyn.\r\n\r\nM=1, B=1 - Since they have the same no of candies, they stop quarreling.\r\n\r\nTotal candies left: 2 \r\n\r\n  Output:\r\n  y = 2\r\n","description_html":"\u003cp\u003eMelvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates.\r\nCan you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\nx = [5 3]\r\n\u003c/pre\u003e\u003cp\u003eExplanation:\r\nDenoting Melvyn as M, Banner as B\u003c/p\u003e\u003cp\u003eM=5, B=3 - Banner eats 3 chocolates of Melvyn.\u003c/p\u003e\u003cp\u003eM=2, B=3 - Melvyn eats 2 chocolates of Banner.\u003c/p\u003e\u003cp\u003eM=2, B=1 - Banner eats 1 chocolate of Melvyn.\u003c/p\u003e\u003cp\u003eM=1, B=1 - Since they have the same no of candies, they stop quarreling.\u003c/p\u003e\u003cp\u003eTotal candies left: 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\ny = 2\r\n\u003c/pre\u003e","function_template":"function y = the_deadly_sin(x)\r\n  % Try to be witty. The problem is not that difficult to figure out.\r\nend","test_suite":"%%\r\nx = [5 3];\r\ny_correct = 2;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [10 10];\r\ny_correct = 20;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [4 8];\r\ny_correct = 8;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [30 12];\r\ny_correct = 12;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [42 91];\r\ny_correct = 14;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n\r\n%%\r\nx = [700 80];\r\ny_correct = 40;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [638 899];\r\ny_correct = 58;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [819 949];\r\ny_correct = 26;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n\r\nx = [500 500];\r\ny_correct = 1000;\r\nassert(isequal(the_deadly_sin(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":195572,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-08-02T23:07:17.000Z","updated_at":"2018-08-02T23:08:40.000Z","published_at":"2018-08-02T23:07:17.000Z","restored_at":"2018-10-10T14:57:50.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eMelvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates. Can you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\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:\\nx = [5 3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExplanation: Denoting Melvyn as M, Banner as B\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\u003eM=5, B=3 - Banner eats 3 chocolates of Melvyn.\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\u003eM=2, B=3 - Melvyn eats 2 chocolates of Banner.\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\u003eM=2, B=1 - Banner eats 1 chocolate of Melvyn.\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\u003eM=1, B=1 - Since they have the same no of candies, they stop quarreling.\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\u003eTotal candies left: 2\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:\\ny = 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":54440,"title":"Create an arrow matrix","description":"An arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \r\n                                        \r\n                                        \r\n\r\nWrite a function that takes the number of rows and columns (for N \u003e= 3) as an input, and returns the corresponding arrow matrix.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 305px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 152.5px; transform-origin: 407px 152.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 164px; 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 82px; text-align: left; transform-origin: 384px 82px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003cimg class=\"imageNode\" width=\"199\" height=\"158\" style=\"vertical-align: baseline;width: 199px;height: 158px\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMy4yMDQgMjUzMy40OSAzMzMuMjA0IDI1MzMuNDkgNjM3LjU1IDIxMzcuMiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjUzMy40OSAzMzMuMjA0IDI5MjkuNzcgMzMzLjIwNCAyOTI5Ljc3IDYzNy41NSAyNTMzLjQ5IDYzNy41NVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDYzNy41NSAxMzQ0LjYzIDYzNy41NSAxMzQ0LjYzIDk1NC43NCA5NDguMzQ5IDk1NC43NFoiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDYzNy41NSAxNzQwLjkyIDYzNy41NSAxNzQwLjkyIDk1NC43NCAxMzQ0LjYzIDk1NC43NFoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDYzNy41NSAyMTM3LjIgNjM3LjU1IDIxMzcuMiA5NTQuNzQgMTc0MC45MiA5NTQuNzRaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDYzNy41NSAyNTMzLjQ5IDYzNy41NSAyNTMzLjQ5IDk1NC43NCAyMTM3LjIgOTU0Ljc0WiIgZmlsbD0iI0Y4Q0JBRCIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgNjM3LjU1IDI5MjkuNzcgNjM3LjU1IDI5MjkuNzcgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgOTU0Ljc0IDEzNDQuNjMgOTU0Ljc0IDEzNDQuNjMgMTI3MS45MyA5NDguMzQ5IDEyNzEuOTNaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyA5NTQuNzQgMTc0MC45MiA5NTQuNzQgMTc0MC45MiAxMjcxLjkzIDEzNDQuNjMgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDk1NC43NCAyMTM3LjIgOTU0Ljc0IDIxMzcuMiAxMjcxLjkzIDE3NDAuOTIgMTI3MS45M1oiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0IDI1MzMuNDkgMTI3MS45MyAyMTM3LjIgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDk1NC43NCAyOTI5Ljc3IDk1NC43NCAyOTI5Ljc3IDEyNzEuOTMgMjUzMy40OSAxMjcxLjkzWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMTI3MS45MyAxMzQ0LjYzIDEyNzEuOTMgMTM0NC42MyAxNTg5LjEyIDk0OC4zNDkgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDEyNzEuOTMgMTc0MC45MiAxMjcxLjkzIDE3NDAuOTIgMTU4OS4xMiAxMzQ0LjYzIDE1ODkuMTJaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAxMjcxLjkzIDIxMzcuMiAxMjcxLjkzIDIxMzcuMiAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgMTI3MS45MyAyNTMzLjQ5IDEyNzEuOTMgMjUzMy40OSAxNTg5LjEyIDIxMzcuMiAxNTg5LjEyWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMTI3MS45MyAyOTI5Ljc3IDEyNzEuOTMgMjkyOS43NyAxNTg5LjEyIDI1MzMuNDkgMTU4OS4xMloiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDE1ODkuMTIgMTM0NC42MyAxNTg5LjEyIDEzNDQuNjMgMTkwNi4zMSA5NDguMzQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMiAxNzQwLjkyIDE5MDYuMzEgMTM0NC42MyAxOTA2LjMxWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTE3NDAuOTIgMTU4OS4xMiAyMTM3LjIgMTU4OS4xMiAyMTM3LjIgMTkwNi4zMSAxNzQwLjkyIDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDE1ODkuMTIgMjUzMy40OSAxNTg5LjEyIDI1MzMuNDkgMTkwNi4zMSAyMTM3LjIgMTkwNi4zMVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDE1ODkuMTIgMjkyOS43NyAxNTg5LjEyIDI5MjkuNzcgMTkwNi4zMSAyNTMzLjQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAzMzAuOTEyIDEzNDQuNjMgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzAuOTEyIDE3NDAuOTIgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMC45MTIgMjEzNy4yIDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMzMwLjkxMiAyNTMzLjQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggNjM3LjU1IDI5MzIuMDYgNjM3LjU1IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCA5NTQuNzQgMjkzMi4wNiA5NTQuNzQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDEyNzEuOTMgMjkzMi4wNiAxMjcxLjkzIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCAxNTg5LjEyIDI5MzIuMDYgMTU4OS4xMiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMzMwLjkxMiA5NDguMzQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI5MjkuNzcgMzMwLjkxMiAyOTI5Ljc3IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggMzMzLjIwNCAyOTMyLjA2IDMzMy4yMDQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDE5MDYuMzEgMjkzMi4wNiAxOTA2LjMxIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48dGV4dCBmb250LWZhbWlseT0iQ2FsaWJyaSxDYWxpYnJpX01TRm9udFNlcnZpY2Usc2Fucy1zZXJpZiIgZm9udC13ZWlnaHQ9IjQwMCIgZm9udC1zaXplPSIxMjgiIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIDEgMTExMy44NCA1MjgpIj4xPHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjAiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMzExIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjM5Ni4yODUiIHk9IjMxMSI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSI3OTIuNTciIHk9IjMxMSI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIzMTEiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTU4NS4xNCIgeT0iMzExIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjAiIHk9IjYyOCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSI2MjgiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iNzkyLjU3IiB5PSI2MjgiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\" data-image-state=\"image-loaded\"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of rows and columns (for \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eN\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = arrow(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1; 0 1 1; 1 1 1];\r\nassert(isequal(arrow(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [1 0 0 0 0 1; 0 1 0 0 0 1; 0 0 1 0 0 1; 0 0 0 1 0 1; 0 0 0 0 1 1; 1 1 1 1 1 1];\r\nassert(isequal(arrow(x),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":1,"created_by":571375,"edited_by":571375,"edited_at":"2022-10-03T14:11:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":560,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-05-03T17:40:18.000Z","updated_at":"2026-03-20T13:55:48.000Z","published_at":"2022-10-03T14:11:46.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\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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\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\u003e                                        \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"158\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"199\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\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\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\u003eWrite a function that takes the number of rows and columns (for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.svg+xml\",\"relationshipId\":\"rId1\"}]},{\"partUri\":\"/media/image1.svg+xml\",\"contentType\":\"image/svg+xml\",\"content\":\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMy4yMDQgMjUzMy40OSAzMzMuMjA0IDI1MzMuNDkgNjM3LjU1IDIxMzcuMiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjUzMy40OSAzMzMuMjA0IDI5MjkuNzcgMzMzLjIwNCAyOTI5Ljc3IDYzNy41NSAyNTMzLjQ5IDYzNy41NVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDYzNy41NSAxMzQ0LjYzIDYzNy41NSAxMzQ0LjYzIDk1NC43NCA5NDguMzQ5IDk1NC43NFoiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDYzNy41NSAxNzQwLjkyIDYzNy41NSAxNzQwLjkyIDk1NC43NCAxMzQ0LjYzIDk1NC43NFoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDYzNy41NSAyMTM3LjIgNjM3LjU1IDIxMzcuMiA5NTQuNzQgMTc0MC45MiA5NTQuNzRaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDYzNy41NSAyNTMzLjQ5IDYzNy41NSAyNTMzLjQ5IDk1NC43NCAyMTM3LjIgOTU0Ljc0WiIgZmlsbD0iI0Y4Q0JBRCIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgNjM3LjU1IDI5MjkuNzcgNjM3LjU1IDI5MjkuNzcgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgOTU0Ljc0IDEzNDQuNjMgOTU0Ljc0IDEzNDQuNjMgMTI3MS45MyA5NDguMzQ5IDEyNzEuOTNaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyA5NTQuNzQgMTc0MC45MiA5NTQuNzQgMTc0MC45MiAxMjcxLjkzIDEzNDQuNjMgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDk1NC43NCAyMTM3LjIgOTU0Ljc0IDIxMzcuMiAxMjcxLjkzIDE3NDAuOTIgMTI3MS45M1oiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0IDI1MzMuNDkgMTI3MS45MyAyMTM3LjIgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDk1NC43NCAyOTI5Ljc3IDk1NC43NCAyOTI5Ljc3IDEyNzEuOTMgMjUzMy40OSAxMjcxLjkzWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMTI3MS45MyAxMzQ0LjYzIDEyNzEuOTMgMTM0NC42MyAxNTg5LjEyIDk0OC4zNDkgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDEyNzEuOTMgMTc0MC45MiAxMjcxLjkzIDE3NDAuOTIgMTU4OS4xMiAxMzQ0LjYzIDE1ODkuMTJaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAxMjcxLjkzIDIxMzcuMiAxMjcxLjkzIDIxMzcuMiAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgMTI3MS45MyAyNTMzLjQ5IDEyNzEuOTMgMjUzMy40OSAxNTg5LjEyIDIxMzcuMiAxNTg5LjEyWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMTI3MS45MyAyOTI5Ljc3IDEyNzEuOTMgMjkyOS43NyAxNTg5LjEyIDI1MzMuNDkgMTU4OS4xMloiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDE1ODkuMTIgMTM0NC42MyAxNTg5LjEyIDEzNDQuNjMgMTkwNi4zMSA5NDguMzQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMiAxNzQwLjkyIDE5MDYuMzEgMTM0NC42MyAxOTA2LjMxWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTE3NDAuOTIgMTU4OS4xMiAyMTM3LjIgMTU4OS4xMiAyMTM3LjIgMTkwNi4zMSAxNzQwLjkyIDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDE1ODkuMTIgMjUzMy40OSAxNTg5LjEyIDI1MzMuNDkgMTkwNi4zMSAyMTM3LjIgMTkwNi4zMVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDE1ODkuMTIgMjkyOS43NyAxNTg5LjEyIDI5MjkuNzcgMTkwNi4zMSAyNTMzLjQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAzMzAuOTEyIDEzNDQuNjMgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzAuOTEyIDE3NDAuOTIgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMC45MTIgMjEzNy4yIDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMzMwLjkxMiAyNTMzLjQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggNjM3LjU1IDI5MzIuMDYgNjM3LjU1IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCA5NTQuNzQgMjkzMi4wNiA5NTQuNzQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDEyNzEuOTMgMjkzMi4wNiAxMjcxLjkzIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCAxNTg5LjEyIDI5MzIuMDYgMTU4OS4xMiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMzMwLjkxMiA5NDguMzQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI5MjkuNzcgMzMwLjkxMiAyOTI5Ljc3IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggMzMzLjIwNCAyOTMyLjA2IDMzMy4yMDQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDE5MDYuMzEgMjkzMi4wNiAxOTA2LjMxIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48dGV4dCBmb250LWZhbWlseT0iQ2FsaWJyaSxDYWxpYnJpX01TRm9udFNlcnZpY2Usc2Fucy1zZXJpZiIgZm9udC13ZWlnaHQ9IjQwMCIgZm9udC1zaXplPSIxMjgiIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIDEgMTExMy44NCA1MjgpIj4xPHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjAiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMzExIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjM5Ni4yODUiIHk9IjMxMSI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSI3OTIuNTciIHk9IjMxMSI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIzMTEiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTU4NS4xNCIgeT0iMzExIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjAiIHk9IjYyOCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSI2MjgiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iNzkyLjU3IiB5PSI2MjgiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":61020,"title":"The Case of the Missing Prototype - Count the Fingerprints Found at the Lab Door to Begin Your Investigation","description":"You arrive at the Innovation Lab where the secret prototype was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector prints.\r\nHere, 1 represents a fingerprint found and 0 means a clean spot.\r\nYour first task as Detective Alex Verma is to count the total number of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\r\nReturn a single number — the count of 1s in prints.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 76.5px; transform-origin: 408px 76.5px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou arrive at the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eInnovation Lab\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e where the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003esecret prototype\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eprints\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHere, \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e1\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e represents a\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e fingerprint found\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e0\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e means a \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eclean spot\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour first task as Detective Alex Verma is to \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ecount the total number\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a single number — the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ecount of \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e1\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eprints\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function count = countFingerprints(prints)\r\n  y = x;\r\nend","test_suite":"%%\r\nprints = [1 0 1 1 0 0 1];\r\nprints_correct = 4;\r\nassert(isequal(countFingerprints(prints),prints_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":4953963,"edited_at":"2025-10-20T15:41:28.000Z","deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T15:39:33.000Z","updated_at":"2026-04-03T03:44:06.000Z","published_at":"2025-10-20T15:41:28.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\u003eYou arrive at the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInnovation Lab\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e where the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esecret prototype\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprints\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e represents a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e fingerprint found\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e means a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eclean spot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour first task as Detective Alex Verma is to \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecount the total number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\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\u003eReturn a single number — the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecount of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprints\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":1991,"title":"Find the index of nth maximum of a row vector of real numbers","description":"Given a vector of real numbers x, find the index idx of _n_ th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\r\n\r\n*Example 1:*\r\n\r\nInput: x = [2 4.5 3 1 3.33], n = 4\r\n\r\nOutput: idx = 1, since 4th maximum is 2\r\n\r\n*Example 2:*\r\nInput: x = [2 4.5 3.33 3 1 3.33], n = 2\r\n\r\nOutput: idx = [3 6], since 2nd maximum is 3.33\r\n","description_html":"\u003cp\u003eGiven a vector of real numbers x, find the index idx of \u003ci\u003en\u003c/i\u003e th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample 1:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eInput: x = [2 4.5 3 1 3.33], n = 4\u003c/p\u003e\u003cp\u003eOutput: idx = 1, since 4th maximum is 2\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample 2:\u003c/b\u003e\r\nInput: x = [2 4.5 3.33 3 1 3.33], n = 2\u003c/p\u003e\u003cp\u003eOutput: idx = [3 6], since 2nd maximum is 3.33\u003c/p\u003e","function_template":"function idx = findMaxIndex(x,n)\r\n% Enter your code here\r\nend","test_suite":"%%\r\nx = [2 4.5 3 1 3.33]; n = 4;\r\ny_correct = 1;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33]; n = 5;\r\ny_correct = 4;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01]; n = 1;\r\ny_correct = 7;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01]; n = 8;\r\ny_correct = 6;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01 realmax realmin]; n = 2;\r\ny_correct = 9;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [-2.23 1 0 -6.65 2.63 -realmax inf 0]; n = 8\r\ny_correct = 6;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3.33 3 1 3.33]; n = 2;\r\ny_correct = [3 6];\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 pi eps eps pi 0 pi 6]; n = 3;\r\ny_correct = [3 6 8];\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":18241,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2013-11-16T05:39:46.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-11-15T15:19:06.000Z","updated_at":"2026-03-23T11:12:29.000Z","published_at":"2013-11-15T15:19: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\u003eGiven a vector of real numbers x, find the index idx of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: x = [2 4.5 3 1 3.33], n = 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\u003eOutput: idx = 1, since 4th maximum is 2\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Input: x = [2 4.5 3.33 3 1 3.33], n = 2\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\u003eOutput: idx = [3 6], since 2nd maximum is 3.33\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":1911,"title":"Find the index of the first occurrence of a value in a matrix","description":"Given a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. For example\r\n \r\n input =\r\n\r\n     0     0     0     0\r\n    -1    -1     0     1\r\n    -1     1     0    -1\r\n     0     0     0     1\r\n\r\nFind row number of first instance of -1 in each column\r\n\r\n output = [2 2 NaN 3]\r\n\r\n\r\n","description_html":"\u003cp\u003eGiven a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. For example\u003c/p\u003e\u003cpre\u003e input =\u003c/pre\u003e\u003cpre\u003e     0     0     0     0\r\n    -1    -1     0     1\r\n    -1     1     0    -1\r\n     0     0     0     1\u003c/pre\u003e\u003cp\u003eFind row number of first instance of -1 in each column\u003c/p\u003e\u003cpre\u003e output = [2 2 NaN 3]\u003c/pre\u003e","function_template":"function y = findfirst(x)\r\n  y = (x==-1);\r\nend","test_suite":"%%\r\nx = [0 1;-1 0];\r\ny_correct = [2 NaN];\r\nassert(isequaln(findfirst(x),y_correct))\r\n\r\n%%\r\nx = [0 0 -1;2 -1 0];\r\ny_correct = [NaN 2 1];\r\nassert(isequaln(findfirst(x),y_correct))\r\n\r\n%%\r\nx = [0 1 0 -1;-1 -1 0 1;-1 1 0 -1;0 0 0 1];\r\ny_correct = [2 2 NaN 1];\r\nassert(isequaln(findfirst(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":11070,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-03T02:46:18.000Z","updated_at":"2025-02-06T02:49:16.000Z","published_at":"2013-10-03T02:46:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. 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[ input =\\n\\n     0     0     0     0\\n    -1    -1     0     1\\n    -1     1     0    -1\\n     0     0     0     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\u003eFind row number of first instance of -1 in each column\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 NaN 3]]]\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":61034,"title":"The MATLAB Treasure Hunt – Identify the Hidden Pattern Within the Maze of Numbers","description":"The compass leads you to an underground chamber covered in numbers carved into the walls — a maze of digits that glows in mysterious patterns.\r\nThe inscription reads: “Only the even paths shall open.”\r\nGiven a vector a of numbers, extract and return a new vector b containing only the even numbers, preserving their original order.\r\nThese even numbers form the correct path through the Maze of Numbers.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 76.5px; transform-origin: 408px 76.5px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe compass leads you to an underground chamber covered in numbers carved into the walls — a \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003emaze of digits\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e that glows in mysterious patterns.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe inscription reads: \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e“Only the even paths shall open.”\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ea\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of numbers, extract and return a new vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eb\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e containing \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eonly the even numbers\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, preserving their original order.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThese even numbers form the correct path through the Maze of Numbers.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y =mazePath(a)\r\n  y = x;\r\nend","test_suite":"%%\r\na = [3 8 11 24 19 42];\r\ny_correct = [8 24 42];\r\nassert(isequal(mazePath(a),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-21T09:32:24.000Z","updated_at":"2026-03-10T12:47:56.000Z","published_at":"2025-10-21T09:32:24.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\u003eThe compass leads you to an underground chamber covered in numbers carved into the walls — a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emaze of digits\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that glows in mysterious patterns.\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 inscription reads: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e“Only the even paths shall open.”\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\u003eGiven a vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of numbers, extract and return a new vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e containing \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eonly the even numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, preserving their original order.\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\u003eThese even numbers form the correct path through the Maze of Numbers.\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":61026,"title":"The Case of the Missing Prototype – Detect Tampered Sensor Readings from the Stolen Device’s Data Logs","description":"You’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector data, but something seems off — certain values are negative, indicating possible tampering.\r\nYour task as Detective Alex Verma is to identify all readings that were tampered with.\r\nReturn a row vector containing the indices of all negative values in data.\r\nIf no tampering is found, return an empty vector.\r\nEvery negative entry is another clue toward catching the thief!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 162px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 81px; transform-origin: 408px 81px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003edata\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, but something seems off — certain values are \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003enegative\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, indicating possible tampering.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour task as Detective Alex Verma is to identify all readings that were tampered with.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a row vector containing the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eindices\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of all negative values in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003edata\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf no tampering is found, return an empty vector.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEvery negative entry is another clue toward catching the thief!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = detectTampering(data)\r\n  y = x;\r\nend","test_suite":"%%\r\ndata = [2 -5 3 -1 6];\r\ny_correct = [2 4];\r\nassert(isequal(detectTampering(data),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":51,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T16:55:42.000Z","updated_at":"2026-04-03T03:56:39.000Z","published_at":"2025-10-20T16:55:42.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\u003eYou’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edata\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, but something seems off — certain values are \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enegative\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicating possible tampering.\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\u003eYour task as Detective Alex Verma is to identify all readings that were tampered with.\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\u003eReturn a row vector containing the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eindices\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of all negative values in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edata\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no tampering is found, return an empty vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery negative entry is another clue toward catching the thief!\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\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":42675,"title":"Get all corner elements from a matrix where dimension of matrix is always equal to or greater than 2.","description":"if a given matrix a  = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]","description_html":"\u003cp\u003eif a given matrix a  = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 1;1 1];\r\ny_correct = [1 1;1 1];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [1 2 3;4 5 6];\r\ny_correct = [1 3;4 6];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [1 2 3 4;1 1 1 1;0 0 0 0;5 6 7 8];\r\ny_correct = [1 4;5 8];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":104,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-30T13:31:12.000Z","updated_at":"2026-02-15T08:52:10.000Z","published_at":"2015-10-30T13:39: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\",\"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\u003eif a given matrix a = [1 2 3;4 5 6]; so answer is going to be [1 3;4 6]\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":59546,"title":"Getting values from a vector","description":"This exercise is for finding the values that meet your criteria.\r\na = [-5 28 7 83 73];\r\nb = 23 ;\r\nc = (a \u003e b)\r\nThen :\r\nc = \r\n   0   1   0   1   1\r\nWhat we are looking for now is how to get the values :\r\ny =     \r\n    28    83    73\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 287.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 143.525px; transform-origin: 407px 143.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThis exercise is for finding the values that meet your criteria.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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 30.65px; transform-origin: 404px 30.6562px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ea = [-5 28 7 83 73];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eb = 23 ;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ec = (a \u0026gt; b)\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThen :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.875px; 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.4375px; transform-origin: 404px 20.4375px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ec = \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e   0   1   0   1   1\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWhat we are looking for now is how to get the values :\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.875px; 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.4375px; transform-origin: 404px 20.4375px; 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.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey =     \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.8px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.8px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.8px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.8px; 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.2125px; text-wrap: nowrap; transform-origin: 404px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e    28    83    73\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-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  \r\nend","test_suite":"%%\r\nx = [17 85 -20 99];\r\ny_correct = [85 99];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [-5 28 7 83 73];\r\ny_correct = [28 83 73];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [55 0 7 53];\r\ny_correct = [55 53];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [80 0 -90];\r\ny_correct = [80];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [10 14 -80 30 -95];\r\ny_correct = [30];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":4033021,"edited_by":4033021,"edited_at":"2024-01-10T06:33:06.000Z","deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":"2024-01-10T06:33:06.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-01-09T17:51:26.000Z","updated_at":"2026-04-02T13:30:37.000Z","published_at":"2024-01-09T18:04:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis exercise is for finding the values that meet your criteria.\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 = [-5 28 7 83 73];\\nb = 23 ;\\nc = (a \u003e b)]]\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\u003eThen :\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[c = \\n   0   1   0   1   1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat we are looking for now is how to get the values :\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 =     \\n    28    83    73]]\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":42678,"title":"For a given linear index as input for n sized square matrix, find corresponding row and column.","description":"If input is 1, the row and column will be 1 and 1 respectively.","description_html":"\u003cp\u003eIf input is 1, the row and column will be 1 and 1 respectively.\u003c/p\u003e","function_template":"function rc = your_fcn_name(i,n)\r\n  % i is index and n is length of matrix \r\nend","test_suite":"%%\r\ni = 1;n = 1;\r\ny_correct = [1,1];\r\nassert(isequal(your_fcn_name(i,n),y_correct))\r\n%%\r\ni = 7;n = 3;\r\ny_correct = [1,3];\r\nassert(isequal([your_fcn_name(i,n)],y_correct))\r\n%%\r\ni = 16;n = 7;\r\ny_correct = [2,3];\r\nassert(isequal([your_fcn_name(i,n)],y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":3,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":"2015-10-31T18:52:14.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2015-10-31T16:23:03.000Z","updated_at":"2026-02-06T09:45:23.000Z","published_at":"2015-10-31T16:38: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\",\"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\u003eIf input is 1, the row and column will be 1 and 1 respectively.\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":2121,"title":"Find offset of given matrix element from first matrix element","description":"Given matrix m and an element of that matrix, return the offset from its first element.\r\ne.g. m=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51\r\nThen, offset = 5\r\n\r\nReturn 0, if that element if not a matrix element","description_html":"\u003cp\u003eGiven matrix m and an element of that matrix, return the offset from its first element.\r\ne.g. m=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51\r\nThen, offset = 5\u003c/p\u003e\u003cp\u003eReturn 0, if that element if not a matrix element\u003c/p\u003e","function_template":"function offset= FindOffset(m, element)\r\n  y = x;\r\nend","test_suite":"%%\r\nm=[11 2 34; 40 51 6; 87 8 109]\r\nelement = 51;\r\noffset = 5;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=reshape([1:10],5,2);\r\nelement = 9;\r\noffset = 9;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=eye(7);\r\nelement = 0;\r\noffset = 2;\r\nassert(isequal(FindOffset(m,element),offset));\r\n\r\n%%\r\nm=[10 20 30 40; 50 60 70 80;];\r\nelement = 56;\r\noffset = 0;\r\nassert(isequal(FindOffset(m,element),offset));\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":85,"test_suite_updated_at":"2014-01-15T19:28:24.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-01-15T19:21:32.000Z","updated_at":"2026-02-28T08:07:23.000Z","published_at":"2014-01-15T19:21:46.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix m and an element of that matrix, return the offset from its first element. e.g. m=[11 2 34; 40 51 6; 87 8 109] element = 51 Then, offset = 5\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\u003eReturn 0, if that element if not a matrix element\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":44326,"title":"Replace 0 indices in array with 1's","description":"Take a incoming vector, and replace 0's with ones","description_html":"\u003cp\u003eTake a incoming vector, and replace 0's with ones\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = ...;\r\nend","test_suite":"%%\r\nx = -1:1:3\r\ny_correct = [-1 1 1 2 3];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":143,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:22:35.000Z","updated_at":"2026-02-09T17:09:04.000Z","published_at":"2017-09-14T17:22:35.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eTake a incoming vector, and replace 0's with ones\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":43655,"title":"Where is the number that you want to find?","description":"For a given matrix A, find where the input number x appears.\r\nDo this task by returning the vector which contains the row and the column as its element \r\n\r\nExample\r\n\r\n A = [1 5 6 7]\r\n x = 7\r\n\r\n output = [1 4]\r\n\r\n","description_html":"\u003cp\u003eFor a given matrix A, find where the input number x appears.\r\nDo this task by returning the vector which contains the row and the column as its element\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e A = [1 5 6 7]\r\n x = 7\u003c/pre\u003e\u003cpre\u003e output = [1 4]\u003c/pre\u003e","function_template":"function y = indexmynum(A,x)\r\n\r\nend","test_suite":"%%\r\nA=magic(4)\r\nx=1\r\ny_correct = [4 4]\r\nassert(isequal(indexmynum(A,x),y_correct))\r\n%%\r\nA=magic(6)\r\nx=22\r\ny_correct = [3 4]\r\nassert(isequal(indexmynum(A,x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":88437,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":94,"test_suite_updated_at":"2016-11-14T05:34:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2016-11-14T05:26:20.000Z","updated_at":"2026-02-13T16:34:31.000Z","published_at":"2016-11-14T05:26:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor a given matrix A, find where the input number x appears. Do this task by returning the vector which contains the row and the column as its element\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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 5 6 7]\\n x = 7\\n\\n output = [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":47118,"title":"find the index of a number","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 111px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 55.5px; transform-origin: 407px 55.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven a number  and  a single digit number as the input.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFind the index of  that single digit number. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003efor eg. a=83456,  x=4\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eoutput should be y=3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(a,x)\r\n  y = x;\r\nend","test_suite":"%%\r\na=1234;\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=82356;\r\nx = 5;\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=1231;\r\nx = 1;\r\ny_correct = [1,4];\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n\r\n%%\r\na=76454;\r\nx = 4;\r\ny_correct = [3,5];\r\nassert(isequal(your_fcn_name(a,x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":628208,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":50,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-10-29T02:30:31.000Z","updated_at":"2026-02-13T18:28:19.000Z","published_at":"2020-10-29T02:48:08.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a number  and  a single digit number as the input.\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\u003eFind the index of  that single digit 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efor eg. a=83456,  x=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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput should be y=3\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":44242,"title":"Replace Nan!","description":"Replace Nan in the given vector(v) with 9999.","description_html":"\u003cp\u003eReplace Nan in the given vector(v) with 9999.\u003c/p\u003e","function_template":"function y = ReplaceNan(v)\r\n  y = v;\r\nend","test_suite":"%%\r\nx=[1 2 3 0/0 4];\r\ny_correct = [1 2 3 9999 4];\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n\r\n%%\r\nx=[5:9];\r\ny_correct =[5:9];\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n\r\n%%\r\nx=repmat(0/0,1,10);\r\ny_correct = repmat(9999,1,10);\r\nassert(isequal(ReplaceNan(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":102298,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-06-27T13:30:08.000Z","updated_at":"2026-02-13T18:08:24.000Z","published_at":"2017-06-27T13:33:17.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\u003eReplace Nan in the given vector(v) with 9999.\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":57570,"title":" An array is given that contains the marks. Find out the highest 3 marks ","description":" An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\r\nFor example if x=[12 5 12.5 10 13 14 8]\r\nOutput will be y=[14 13 12.5]","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 102.017px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.989px 51.0085px; transform-origin: 406.996px 51.0085px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.017px; 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: 383.991px 21.0085px; text-align: left; transform-origin: 383.999px 21.0085px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eFor example if x=[12 5 12.5 10 13 14 8]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eOutput will be y=[14 13 12.5]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [ 9, 6, 7, 6.5, 8, 9.5, 8, 9.5, 8, 8.5, 6, 7, 9];\r\ny_correct = [9.5,9, 8.5];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = [ 93, 97, 67,84,91,81,56,67,55,67,45,98,56,55,44,44,44,91,78];\r\ny_correct = [98,97, 93];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":2294940,"edited_by":2294940,"edited_at":"2023-01-20T10:16:19.000Z","deleted_by":null,"deleted_at":null,"solvers_count":24,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-18T17:47:08.000Z","updated_at":"2026-02-11T14:59:28.000Z","published_at":"2023-01-18T17:47:15.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\u003e An array is given that contains the marks received by a group of students in their class test. Find out the highest 3 marks received by the students?\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 if x=[12 5 12.5 10 13 14 8]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOutput will be y=[14 13 12.5]\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":57585,"title":"Given a matrix X, manipulate it accordingly ","description":"Given a matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same column. For example \r\n➢ Input: x= [2,5; 3,8]\r\n➢ Output: y= [2,5,7; 3,8,11;5,13,18]","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 102.017px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 406.989px 51.0085px; transform-origin: 406.996px 51.0085px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 42.017px; 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: 383.991px 21.0085px; text-align: left; transform-origin: 383.999px 21.0085px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eGiven a matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same column. For example \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e➢ Input: x= [2,5; 3,8]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21.0085px; 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: 383.991px 10.4972px; text-align: left; transform-origin: 383.999px 10.5043px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e➢ Output: y= [2,5,7; 3,8,11;5,13,18]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx= [2,5; 3,8];\r\ny_correct = [2,5,7; 3,8,11;5,13,18]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=magic(6);\r\ny_correct=[35     1     6    26    19    24   111;3    32     7    21    23    25   111;31     9     2    22    27    20   111;8    28    33    17    10    15   111;30     5    34    12    14    16   111;4    36    29    13    18    11   111;111   111   111   111   111   111   666];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx= [1,2,3; 4,5,6;7,8,9]\r\ny_correct = [1, 2, 3, 6; 4, 5, 6, 15; 7, 8, 9, 24;\r\n12,15,18,45]\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":2294940,"edited_by":2294940,"edited_at":"2023-01-20T10:15:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":20,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-01-20T10:12:56.000Z","updated_at":"2026-02-06T16:02:03.000Z","published_at":"2023-01-20T10:12:56.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 matrix X, 1st add a column to the matrix whose elements are the summation of each rows. Then add a row to the matrix whose elements are the summation of all elements above in the same 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=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e➢ Input: x= [2,5; 3,8]\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\u003e➢ Output: y= [2,5,7; 3,8,11;5,13,18]\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":2092,"title":"Find offset of an element of a multi dimensional matrix","description":"For a given multi dimensional matrix and given element, find its offset from the 1st element. \r\n\r\nReturn 0, if element is not found in the matrix. \r\n\r\nIf the element is repeated in the matrix, then return the offset of its first occurrence in the matrix. \r\n\r\nE.g. \r\nM(:,:,1) = [1 2 3; 4 5 6]\r\nM(:,:,2) = [10 20 30; 40 50 60]\r\n\r\nElement is 50, then its offset = 10\r\n\r\n","description_html":"\u003cp\u003eFor a given multi dimensional matrix and given element, find its offset from the 1st element.\u003c/p\u003e\u003cp\u003eReturn 0, if element is not found in the matrix.\u003c/p\u003e\u003cp\u003eIf the element is repeated in the matrix, then return the offset of its first occurrence in the matrix.\u003c/p\u003e\u003cp\u003eE.g. \r\nM(:,:,1) = [1 2 3; 4 5 6]\r\nM(:,:,2) = [10 20 30; 40 50 60]\u003c/p\u003e\u003cp\u003eElement is 50, then its offset = 10\u003c/p\u003e","function_template":"function offset = FindOffset(matrix, element)\r\n  offset = 0;\r\nend","test_suite":"%%\r\nclear all;\r\nM(:,:,1) = [1 2 3; 4 5 6];\r\nM(:,:,2) = [10 20 30; 40 50 60];\r\nElement = 50;\r\ny_correct = 10;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 2 3; 4 5 6];\r\nM(:,:,2) = [10 20 30; 40 50 60];\r\nM(:,:,3) = [100 200 300; 400 500 600];\r\n\r\nElement = 6;\r\ny_correct = 6;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 0 0; 0 1 0]\r\nM(:,:,2) = [1 0 1; 1 1 0]\r\nM(:,:,3) = [1 1 1; 0 0 0]\r\n\r\nElement = 0;\r\ny_correct = 2;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n\r\n%%\r\nclear all;\r\nM(:,:,1,1) = [10 20 350; 30 1 50]\r\nM(:,:,2,1) = [12 0 11; 13 15 60]\r\nM(:,:,1,2) = [4 5 6; 70 80 100]\r\nM(:,:,2,2) = [1000 2000 3000; 4000 5000 6000]\r\n\r\nElement = 70;\r\ny_correct = 14;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n\r\n%%\r\nclear all;\r\nM(:,:,1) = [1 20 30; 40 5 60]\r\nM(:,:,2) = [89 90 100; 101 135 99]\r\nM(:,:,3) = [6 19 67; 31 41 45]\r\n\r\nElement = 102;\r\ny_correct = 0;\r\nassert(isequal(FindOffset(M, Element),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":"2014-01-07T21:56:03.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2014-01-07T21:30:10.000Z","updated_at":"2026-01-04T08:31:55.000Z","published_at":"2014-01-07T21:31:46.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\u003eFor a given multi dimensional matrix and given element, find its offset from the 1st element.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn 0, if element is not found 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the element is repeated in the matrix, then return the offset of its first occurrence 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eE.g. M(:,:,1) = [1 2 3; 4 5 6] M(:,:,2) = [10 20 30; 40 50 60]\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\u003eElement is 50, then its offset = 10\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":45472,"title":"Find the sum of all integers in a given matrix","description":"Finding sum of all integers in a given matrix","description_html":"\u003cp\u003eFinding sum of all integers in a given matrix\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\n\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\n\r\nx=2\r\ny_correct=2\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\n\r\nx=[1 2]\r\ny_correct=3\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":433466,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":51,"test_suite_updated_at":"2020-04-23T15:21:31.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-22T07:12:24.000Z","updated_at":"2026-02-09T16:35:55.000Z","published_at":"2020-04-22T07:12:24.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\u003eFinding sum of all integers in a given matrix\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":58563,"title":"Convert row and column subscripts to linear indices","description":"Convert 2D row and column subscripts to linear indices WITHOUT sub2ind\r\nExample:\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [3 3];\r\nind = my_sub2ind(sz, row, col)\r\nReturns:\r\nind = 1×4\r\n\r\n     4     5     6     7","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 245.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407.5px 122.531px; transform-origin: 407.5px 122.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eConvert 2D row and column subscripts to linear indices WITHOUT sub2ind\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eExample:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.75px; 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: 404.5px 40.875px; transform-origin: 404.5px 40.875px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003erow = [1 2 3 1];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ecol = [2 2 2 3];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003esz = [3 3];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eind = my_sub2ind(sz, row, col)\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: 384.5px 10.5px; text-align: left; transform-origin: 384.5px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eReturns:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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: 404.5px 30.6562px; transform-origin: 404.5px 30.6562px; 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.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eind = 1\u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(255, 0, 0); border-block-start-color: rgb(255, 0, 0); border-bottom-color: rgb(255, 0, 0); border-inline-end-color: rgb(255, 0, 0); border-inline-start-color: rgb(255, 0, 0); border-left-color: rgb(255, 0, 0); border-right-color: rgb(255, 0, 0); border-top-color: rgb(255, 0, 0); caret-color: rgb(255, 0, 0); color: rgb(255, 0, 0); column-rule-color: rgb(255, 0, 0); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(255, 0, 0); text-decoration: none; text-decoration-color: rgb(255, 0, 0); text-emphasis-color: rgb(255, 0, 0); \"\u003e×\u003c/span\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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: 0.666667px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 0.666667px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 0.666667px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 0.666667px; 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: 404.5px 10.2188px; text-wrap: nowrap; transform-origin: 404.5px 10.2188px; \"\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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space-collapse: preserve; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     4     5     6     7\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function ind = subToLinearIdx(sz, row, col)\r\n  ind = row;\r\nend","test_suite":"%%\r\nrow = [2 1];\r\ncol = [2 2];\r\nsz = [2 2];\r\nind_correct = [4 3];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n\r\n%%\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [3 3];\r\nind_correct = [4 5 6 7];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n\r\n%%\r\nrow = [1 2 3 1];\r\ncol = [2 2 2 3];\r\nsz = [4 3];\r\nind_correct = [5 6 7 9];\r\nfiletext = fileread('subToLinearIdx.m');\r\nassert(isequal(subToLinearIdx(sz, row, col),ind_correct))\r\nassert(isempty(strfind(filetext, 'sub2ind')))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":1,"created_by":3494918,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-07-17T15:13:09.000Z","updated_at":"2026-02-24T10:46:10.000Z","published_at":"2023-07-17T15:13:09.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\u003eConvert 2D row and column subscripts to linear indices WITHOUT sub2ind\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[row = [1 2 3 1];\\ncol = [2 2 2 3];\\nsz = [3 3];\\nind = my_sub2ind(sz, row, col)]]\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\u003eReturns:\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[ind = 1×4\\n\\n     4     5     6     7]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":3107,"title":"Try and Catch Simple Example","description":"Try and Catch Simple Example \r\n\r\n\u003chttp://in.mathworks.com/help/matlab/ref/try.html Example\u003e \r\n\r\nVector x=[1 4 6 8 10];\r\n\r\nCreate a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x. \r\n","description_html":"\u003cp\u003eTry and Catch Simple Example\u003c/p\u003e\u003cp\u003e\u003ca href = \"http://in.mathworks.com/help/matlab/ref/try.html\"\u003eExample\u003c/a\u003e\u003c/p\u003e\u003cp\u003eVector x=[1 4 6 8 10];\u003c/p\u003e\u003cp\u003eCreate a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x.\u003c/p\u003e","function_template":"function y = trcatch(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 4 6 8 10];\r\nn=1;\r\ny_correct = 1;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n%% \r\nfiletext = fileread('trcatch.m');\r\nassert(~isempty(strfind(filetext, 'try')),'try missing')\r\nassert(~isempty(strfind(filetext, 'catch')),'Catch missing')\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=0;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=6;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=5;\r\ny_correct = 10;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=-25;\r\ny_correct = 0;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n\r\n%%\r\nx = [1 4 6 8 10];\r\nn=3;\r\ny_correct = 6;\r\nassert(isequal(trcatch(x,n),y_correct))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":27760,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-03-23T09:12:50.000Z","updated_at":"2026-02-17T08:52:20.000Z","published_at":"2015-03-23T09:12:50.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\u003eTry and Catch Simple Example\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:hyperlink w:docLocation=\\\"http://in.mathworks.com/help/matlab/ref/try.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eExample\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\u003eVector x=[1 4 6 8 10];\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 a function using try and catch, if user asks index 0 or negative or more than the length, then display zero otherwise value of x.\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":42648,"title":"Place numbers","description":"Given two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index number. \r\n\r\nexample is\r\n\r\nfirst input is [1 2 ; 3 4];\r\n\r\nsecond input is [0 3 5 7];\r\n\r\noutput will be [0 3; 5 7];\r\n\r\nsecond example is \r\n\r\nfirst input is [1 2 ; 3 4;5 6; 1 2];\r\n\r\nsecond input is [0 3 5 7 3 2];\r\n\r\noutput will be [0 3; 5 7;3 2; 0 3];\r\n\r\n","description_html":"\u003cp\u003eGiven two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index number.\u003c/p\u003e\u003cp\u003eexample is\u003c/p\u003e\u003cp\u003efirst input is [1 2 ; 3 4];\u003c/p\u003e\u003cp\u003esecond input is [0 3 5 7];\u003c/p\u003e\u003cp\u003eoutput will be [0 3; 5 7];\u003c/p\u003e\u003cp\u003esecond example is\u003c/p\u003e\u003cp\u003efirst input is [1 2 ; 3 4;5 6; 1 2];\u003c/p\u003e\u003cp\u003esecond input is [0 3 5 7 3 2];\u003c/p\u003e\u003cp\u003eoutput will be [0 3; 5 7;3 2; 0 3];\u003c/p\u003e","function_template":"function y = place_number(index,vector)\r\n  \r\nend","test_suite":"%%\r\n\r\nindex = [1 2 ; 3 4];\r\nvector=  [0 3 5 7];\r\ny_correct =[0 3; 5 7];\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 ; 3 4;5 6; 1 2];;\r\nvector=  [0 3 5 7 3 2];\r\ny_correct =[0 3; 5 7;3 2; 0 3];;\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 3; 2 1 3];\r\nvector=  [0 3 5 ];\r\ny_correct =[0 3 5 ;3 0 5];\r\nassert(isequal(place_number(index,vector),y_correct))\r\n\r\n%%\r\nindex = [1 2 3; 4 5 6; 1 2 3;4 5 6];\r\nvector=  1:6;\r\ny_correct =index;\r\nassert(isequal(place_number(index,vector),y_correct));\r\n\r\n%%\r\nindex = [1 2 1 2; 1 2 2 2; 1 2 1 1];\r\nvector=  [6 7];\r\ny_correct =index+5;\r\nassert(isequal(place_number(index,vector),y_correct));\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":22216,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":47,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-10-04T15:41:32.000Z","updated_at":"2026-03-02T14:18:05.000Z","published_at":"2015-10-04T15:42: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven two input first input is a matrix which consist of the index numbers of the second input vector. You place the second input to the first input matrix with respect to the index 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eexample 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efirst input is [1 2 ; 3 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003esecond input is [0 3 5 7];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput will be [0 3; 5 7];\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\u003esecond example 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003efirst input is [1 2 ; 3 4;5 6; 1 2];\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\u003esecond input is [0 3 5 7 3 2];\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput will be [0 3; 5 7;3 2; 0 3];\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":43607,"title":"Logical array indexing - part 1","description":"Given an array |A| of size |p x q| , return an array |Y| of the same size such that the following conditions are satisfied.\r\n\r\n(1) The non-zero elements should be greater than a given value |'n'| .\r\n\r\n(2) These non-zero entries in |Y| should have the same values as their corresponding elements in |A|\r\n\r\nFor example: Given |A = [3 4 5 6 2 4 5 6 3 6]| and |n = 4| , return |Y = [0 0 5 6 0 0 5 6 0 6]|","description_html":"\u003cp\u003eGiven an array \u003ctt\u003eA\u003c/tt\u003e of size \u003ctt\u003ep x q\u003c/tt\u003e , return an array \u003ctt\u003eY\u003c/tt\u003e of the same size such that the following conditions are satisfied.\u003c/p\u003e\u003cp\u003e(1) The non-zero elements should be greater than a given value \u003ctt\u003e'n'\u003c/tt\u003e .\u003c/p\u003e\u003cp\u003e(2) These non-zero entries in \u003ctt\u003eY\u003c/tt\u003e should have the same values as their corresponding elements in \u003ctt\u003eA\u003c/tt\u003e\u003c/p\u003e\u003cp\u003eFor example: Given \u003ctt\u003eA = [3 4 5 6 2 4 5 6 3 6]\u003c/tt\u003e and \u003ctt\u003en = 4\u003c/tt\u003e , return \u003ctt\u003eY = [0 0 5 6 0 0 5 6 0 6]\u003c/tt\u003e\u003c/p\u003e","function_template":"function Y = find_elements(A,n)\r\n  Y = A;\r\nend","test_suite":"%%\r\nA = [3 4 5 6 2 4 5 6 3 6];\r\nn = 4;\r\ny_correct = [0 0 5 6 0 0 5 6 0 6];\r\nassert(isequal(find_elements(A,n),y_correct))\r\n\r\n\r\n%%\r\nA = [0; 6; 1; 7; 3; 5; 2; 4];\r\nn = 3;\r\ny_correct = [0; 6; 0; 7; 0; 5; 0; 4];\r\nassert(isequal(find_elements(A,n),y_correct))\r\n\r\n\r\n%%\r\nA = magic(4);\r\nn = 8;\r\ny_correct = [16 0 0 13; 0 11 10 0; 9 0 0 12; 0 14 15 0];\r\nassert(isequal(find_elements(A,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":70119,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":48,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-24T15:31:58.000Z","updated_at":"2026-03-02T14:23:54.000Z","published_at":"2016-10-24T15:31:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an array\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of size\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ep x q\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , return an array\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of the same size such that the following conditions are satisfied.\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\u003e(1) The non-zero elements should be greater than a given value\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e'n'\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e .\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(2) These non-zero entries in\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e should have the same values as their corresponding elements in\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFor example: Given\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eA = [3 4 5 6 2 4 5 6 3 6]\u003c/w:t\u003e\u003c/w:r\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:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en = 4\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e , return\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:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eY = [0 0 5 6 0 0 5 6 0 6]\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":43144,"title":"BASICS - sum part of vector","description":"Please make a function, where as input you get vector \"x\" and and vector \"c\", where in \"c\" vector you get indexes to sum.\r\nExample:\r\n\r\n  x=[-1 2 3 4 7 9]\r\n  c=[1 4 6]\r\n  y= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12","description_html":"\u003cp\u003ePlease make a function, where as input you get vector \"x\" and and vector \"c\", where in \"c\" vector you get indexes to sum.\r\nExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex=[-1 2 3 4 7 9]\r\nc=[1 4 6]\r\ny= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12\r\n\u003c/pre\u003e","function_template":"function y = sumvec(x,c)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [-1 2 3 4 7 9];\r\nc=[1 4 6];\r\ny_correct = 12;\r\nassert(isequal(sumvec(x,c),y_correct))\r\n\r\n%%\r\nx = [-50 -24 0 4 10 14 19 18];\r\nc=[2 3 6 7];\r\ny_correct = 9;\r\nassert(isequal(sumvec(x,c),y_correct))\r\n","published":true,"deleted":false,"likes_count":26,"comments_count":0,"created_by":90955,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":358,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-10-07T09:19:54.000Z","updated_at":"2026-02-17T09:11:59.000Z","published_at":"2016-10-07T09:19:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ePlease make a function, where as input you get vector \\\"x\\\" and and vector \\\"c\\\", where in \\\"c\\\" vector you get indexes to sum. Example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[x=[-1 2 3 4 7 9]\\nc=[1 4 6]\\ny= x(1)+ x(4) + x(6) = -1 + 4 + 9 = 12]]\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":42679,"title":"Can you reshape the matrix?","description":"Given a matrix A, is it possible to reshape it into another matrix with the given number of rows?","description_html":"\u003cp\u003eGiven a matrix A, is it possible to reshape it into another matrix with the given number of rows?\u003c/p\u003e","function_template":"function y = your_fcn_name(A,row)\r\n  y = \r\nend","test_suite":"%%\r\nA = 1;row =1;\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 1\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 4\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4];row = 2\r\ny_correct = 1;\r\nassert(isequal(your_fcn_name(A,row),y_correct));\r\n%%\r\nA = [1;2;3;4;5];row = 2\r\ny_correct = 0;\r\nassert(isequal(your_fcn_name(A,row),y_correct));","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":28123,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":88,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2015-11-01T13:26:18.000Z","updated_at":"2026-02-17T14:55:47.000Z","published_at":"2015-11-01T13:29:15.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix A, is it possible to reshape it into another matrix with the given number of rows?\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":42982,"title":"Select every other element of a matrix","description":"Write a function called \r\n\r\n  outMat = odd_idx( myMat )\r\n\r\nthat takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.","description_html":"\u003cp\u003eWrite a function called\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eoutMat = odd_idx( myMat )\r\n\u003c/pre\u003e\u003cp\u003ethat takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.\u003c/p\u003e","function_template":"function outMat = odd_idx( myMat )\r\n  outMat = myMat;\r\nend","test_suite":"%%\r\nassert(isequal(odd_idx([1, 2, 3;4, 5, 6;7, 8, 9]),[1, 3;7, 9]))\r\n%%\r\nassert(isequal(odd_idx([16 2 3 13;5 11 10 8;9 7 6 12;4 14 15 1]),[16, 3;9, 6]))\r\n%%\r\nassert(isequal(odd_idx(1), 1))\r\n%%\r\nassert(isequal(odd_idx([1 2]), 1))\r\n%%\r\nassert(isequal(odd_idx([1; 2]), 1))\r\n%%\r\nassert(isequal(odd_idx([7 3 4 7 2 9 4 9 5 8]), [7 4 2 4 5]))\r\n%%\r\nassert(isequal(odd_idx([5;2;8;6;6;10;4;9;6;7]),[5;8;6;4;6]))\r\n%%\r\nassert(isequal(odd_idx([2 4 4 2 2 1;4 2 2 5 2 4;4 2 2 1 2 1;2 3 5 5 1 1;3 4 2 5 5 1;3 5 3 1 4 1;5 2 2 5 5 2]), [2 4 2;  4 2 2;  3 2 5;  5 2 5]))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3338,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":53,"test_suite_updated_at":"2016-09-08T14:58:19.000Z","rescore_all_solutions":true,"group_id":1,"created_at":"2016-09-07T22:55:16.000Z","updated_at":"2026-03-04T14:45:40.000Z","published_at":"2016-09-08T14:52:25.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\u003eWrite a function called\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[outMat = odd_idx( myMat )]]\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 takes a matrix, myMat, as input argument and returns a matrix that contains only those elements of myMat that are in odd rows and columns. In other words, it would return the elements of myMat at indices (1,1), (1,3), (1,5), …, (3,1), (3,3), (3,5), …, etc. Note that both the row and the column of an element must be odd to be included in the output. The following would not be returned: (1,2), (2,1), (2,2) because either the row or the column or both are even. As an example, if myMat were a 5-by-8 matrix, then the output must be 3-by-4 because the function omits rows 2 and 4 of myMat and it also omits columns 2, 4, 6, and 8 of myMat.\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":1741,"title":"Numeric array to cell array of strings (easy)","description":"Given a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\r\n\r\nYou may assume that every element of A is an integer on the interval [1,k].\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  A = [1 2 3\r\n       2 3 1\r\n       3 1 2];\r\n  C = {'yes','no','maybe'};\r\n\r\nThen\r\n\r\n  B = {'yes'    'no'     'maybe'\r\n       'no'     'maybe'  'yes'\r\n       'maybe'  'yes'    'no'};","description_html":"\u003cp\u003eGiven a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\u003c/p\u003e\u003cp\u003eYou may assume that every element of A is an integer on the interval [1,k].\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     2 3 1\r\n     3 1 2];\r\nC = {'yes','no','maybe'};\r\n\u003c/pre\u003e\u003cp\u003eThen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eB = {'yes'    'no'     'maybe'\r\n     'no'     'maybe'  'yes'\r\n     'maybe'  'yes'    'no'};\r\n\u003c/pre\u003e","function_template":"function B = ind2str(A,C)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = [1 2 3\r\n     2 3 1\r\n     3 1 2];\r\nC = {'yes','no','maybe'};\r\nB_correct = {'yes'    'no'     'maybe'\r\n             'no'     'maybe'  'yes'\r\n             'maybe'  'yes'    'no'};\r\nassert(isequal(ind2str(A,C),B_correct))\r\n\r\n%%\r\nA = ones(20,1);\r\nC = {'apples','oranges'};\r\nassert(all(strcmp(ind2str(A,C),'apples')))\r\n\r\n%%\r\nA = randi(1000,[22,10]);\r\nC = arrayfun(@(x) num2str(x),1:1000,'uni',0);\r\nassert(isequal(A,cellfun(@(c) str2num(c),ind2str(A,C))))\r\n\r\n%%\r\nA = randi(2,[1,100]);\r\nC = {'0','1'};\r\nassert(isequal(A-1,cellfun(@(c) str2num(c),ind2str(A,C))))\r\n\r\n%%\r\nA = [2 4 4 2 2 4];\r\nC = {'foo','bar','baz','qux'};\r\nB_correct = {'bar' 'qux' 'qux' 'bar' 'bar' 'qux'};\r\nassert(isequal(ind2str(A,C),B_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":60,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-07-23T17:44:26.000Z","updated_at":"2026-02-27T13:58:55.000Z","published_at":"2013-07-23T17:44:26.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a numeric array (A) and a 1xk cell array of strings (C), return a cell array (B) that is the same size as A and in which each element of B is the string in C indexed by the same element in A.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that every element of A is an integer on the interval [1,k].\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\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\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 3\\n     2 3 1\\n     3 1 2];\\nC = {'yes','no','maybe'};]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[B = {'yes'    'no'     'maybe'\\n     'no'     'maybe'  'yes'\\n     'maybe'  'yes'    'no'};]]\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":43682,"title":"Pairwise column flip","description":"Given matrix *M_in*, flip every pair of columns. So if *M_in* is\r\n\r\n 1 2 3 4\r\n 1 2 3 4\r\n\r\nthen *M_out* is\r\n\r\n 2 1 4 3\r\n 2 1 4 3\r\n\r\nNote: if *M_in* has odd number of columns, the last column should remain unchanged. So if *M_in* 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\nthen *M_out* is\r\n\r\n 24    17     8     1    15\r\n  5    23    14     7    16\r\n  6     4    20    13    22\r\n 12    10    21    19     3\r\n 18    11     2    25     9","description_html":"\u003cp\u003eGiven matrix \u003cb\u003eM_in\u003c/b\u003e, flip every pair of columns. So if \u003cb\u003eM_in\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 1 2 3 4\r\n 1 2 3 4\u003c/pre\u003e\u003cp\u003ethen \u003cb\u003eM_out\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 2 1 4 3\r\n 2 1 4 3\u003c/pre\u003e\u003cp\u003eNote: if \u003cb\u003eM_in\u003c/b\u003e has odd number of columns, the last column should remain unchanged. So if \u003cb\u003eM_in\u003c/b\u003e 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\u003ethen \u003cb\u003eM_out\u003c/b\u003e is\u003c/p\u003e\u003cpre\u003e 24    17     8     1    15\r\n  5    23    14     7    16\r\n  6     4    20    13    22\r\n 12    10    21    19     3\r\n 18    11     2    25     9\u003c/pre\u003e","function_template":"function y = flip_columns(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = 1:5;\r\ny_correct = [2 1 4 3 5];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 4 5];\r\ny_correct = [2 1 4 3 5];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = [0 1 0 0; 1 0 0 0; 0 0 0 1; 0 0 1 0];\r\nassert(isequal(flip_columns(x),y_correct))\r\n\r\n%%\r\nx = magic(5);\r\ny_correct = [24 17  8  1 15; ...\r\n              5 23 14  7 16; ...\r\n              6  4 20 13 22; ...\r\n             12 10 21 19  3; ...\r\n             18 11  2 25  9];\r\nassert(isequal(flip_columns(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":33176,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":44,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-11-23T20:42:15.000Z","updated_at":"2026-02-26T11:56:58.000Z","published_at":"2016-11-23T20:43:29.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, flip every pair of columns. So if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 1 2 3 4\\n 1 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\u003ethen\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\u003eM_out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 2 1 4 3\\n 2 1 4 3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote: if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e has odd number of columns, the last column should remain unchanged. So if\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\u003eM_in\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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\u003ethen\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\u003eM_out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e 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[ 24    17     8     1    15\\n  5    23    14     7    16\\n  6     4    20    13    22\\n 12    10    21    19     3\\n 18    11     2    25     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":56155,"title":"Return the middle element of an NxN square matrix where N is odd","description":"Let's say you are given an NxN square matrix where N is always going to be an odd number:\r\nx = [ 1 2 3\r\n      4 5 6 \r\n      7 8 9 ]\r\nYour function should return 5.\r\n\r\nEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\r\n% Input Matrix\r\nx = []\r\n% Correct answer returned by your function\r\ny = NaN","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 275.062px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 137.527px; transform-origin: 407px 137.531px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eLet's say you are given an NxN square matrix where N is always going to be an odd number:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3125px; 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 30.6518px; transform-origin: 404px 30.6562px; 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.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ex = [ 1 2 3\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      4 5 6 \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e      7 8 9 ]\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYour function should return 5.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.75px; 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 40.875px; transform-origin: 404px 40.875px; 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.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); \"\u003e% Input Matrix\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ex = []\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"border-block-end-color: rgb(2, 128, 9); border-block-start-color: rgb(2, 128, 9); border-bottom-color: rgb(2, 128, 9); border-inline-end-color: rgb(2, 128, 9); border-inline-start-color: rgb(2, 128, 9); border-left-color: rgb(2, 128, 9); border-right-color: rgb(2, 128, 9); border-top-color: rgb(2, 128, 9); caret-color: rgb(2, 128, 9); color: rgb(2, 128, 9); column-rule-color: rgb(2, 128, 9); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(2, 128, 9); text-decoration: none; text-decoration-color: rgb(2, 128, 9); text-emphasis-color: rgb(2, 128, 9); \"\u003e% Correct answer returned by your function\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4375px; 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.2143px; transform-origin: 404px 10.2188px; 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: 0px 0px; tab-size: 4; transform-origin: 0px 0px; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ey = NaN\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = get_middle_element(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(get_middle_element(x),y_correct))\r\n%%\r\nx = [1 2 3; 4 5 6; 7 8 9; 10 11 12; 13 14 15];\r\ny_correct = 8;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [1 2 3];\r\ny_correct = 2;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [1];\r\ny_correct = 1;\r\nassert(isequal(get_middle_element(x),y_correct))\r\n%%\r\nx = [];\r\ny_correct = NaN;\r\nassert(isequaln(get_middle_element(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":427930,"edited_by":427930,"edited_at":"2022-11-29T14:19:23.000Z","deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":"2022-09-30T12:35:25.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2022-09-30T12:25:43.000Z","updated_at":"2026-02-18T14:28:38.000Z","published_at":"2022-09-30T12:35:25.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLet's say you are given an NxN square matrix where N is always going to be an odd number:\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\\n      4 5 6 \\n      7 8 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour function should return 5.\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\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\u003eEdge Case: Your solution must be able to handle empty matrices, and return a NaN in that case like:\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 Matrix\\nx = []\\n% Correct answer returned by your function\\ny = NaN]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":60704,"title":"Convert RGB to Grayscale","description":"Convert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\r\n*Hint: a formula exists!","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: 51px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 25.5px; transform-origin: 407px 25.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space-collapse: preserve; 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: 236.5px 8px; transform-origin: 236.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eConvert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\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-collapse: preserve; 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: 70.0083px 8px; transform-origin: 70.0083px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e*Hint: a formula exists!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function g = RGB_to_gray(x)\r\n  g = 0;\r\nend","test_suite":"%%\r\nx = [0,0,0];\r\ng = 0;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%assert(isequal(RGB_to_gray(x),g))\r\n%%\r\nx = [255,255,255];\r\ng = 255;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [200,220,240];\r\ng = 216.3;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [0,255,0];\r\ng = 149.7;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n%%\r\nx = [0,0,255];\r\ng = 29.1;\r\nassert(abs(RGB_to_gray(x)-g) \u003c 1e-1)\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":4585291,"edited_by":4585291,"edited_at":"2024-08-07T19:08:12.000Z","deleted_by":null,"deleted_at":null,"solvers_count":26,"test_suite_updated_at":"2024-08-07T19:08:12.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2024-08-07T16:17:39.000Z","updated_at":"2026-02-18T14:54:19.000Z","published_at":"2024-08-07T16:17:39.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\u003eConvert a 3 element RGB array to its correspoding grayscale pixel (a scalar)\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\u003e*Hint: a formula exists!\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":1671,"title":"Generate the Matrix!","description":"Given n, generate the following matrix:\r\n\r\n  a = [ n  n-1 n-2 ... 2 1;\r\n       n-1 n-1 n-2 ... 2 1;\r\n       n-2 n-2 n-2 ... 2 1;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        .   .   .   .  . .;\r\n        2   2   2  ... 2 1;\r\n        1   1   1  ... 1 1]\r\n\r\nGood luck!","description_html":"\u003cp\u003eGiven n, generate the following matrix:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ea = [ n  n-1 n-2 ... 2 1;\r\n     n-1 n-1 n-2 ... 2 1;\r\n     n-2 n-2 n-2 ... 2 1;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      .   .   .   .  . .;\r\n      2   2   2  ... 2 1;\r\n      1   1   1  ... 1 1]\r\n\u003c/pre\u003e\u003cp\u003eGood luck!\u003c/p\u003e","function_template":"function y = mat_fun(n)\r\n  y = ones(n);\r\nend","test_suite":"%%\r\nn = 1;\r\ny_correct = 1;\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 2;\r\ny_correct = [2 1; 1 1];\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 3;\r\ny_correct = [3 2 1; 2 2 1; 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n\r\n%%\r\nn = 4;\r\ny_correct = [4 3 2 1; 3 3 2 1; 2 2 2 1; 1 1 1 1]\r\nassert(isequal(mat_fun(n),y_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":2,"created_by":14930,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":125,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-06-21T17:16:38.000Z","updated_at":"2026-03-11T08:53:15.000Z","published_at":"2013-06-21T17:23:38.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven n, generate the following 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 = [ n  n-1 n-2 ... 2 1;\\n     n-1 n-1 n-2 ... 2 1;\\n     n-2 n-2 n-2 ... 2 1;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      .   .   .   .  . .;\\n      2   2   2  ... 2 1;\\n      1   1   1  ... 1 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood 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":45485,"title":"Count the non-zero elements along the diagonals that are immediately next to the main diagonal","description":"Suppose, you are being told to write a matrix, *a* as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to *count only the total non-zero elements along the diagonals* *(Blue and Green mark on the attached image)* *that are immediately next to the main diagonal* *(Red mark on the attached image)* as output *b*. How will you do that?\r\n\r\nExample: a=[1 3;4 2] and b=2;\r\n\r\n\u003chttps://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003e\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eSuppose, you are being told to write a matrix, \u003cb\u003ea\u003c/b\u003e as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to \u003cb\u003ecount only the total non-zero elements along the diagonals\u003c/b\u003e \u003cb\u003e(Blue and Green mark on the attached image)\u003c/b\u003e \u003cb\u003ethat are immediately next to the main diagonal\u003c/b\u003e \u003cb\u003e(Red mark on the attached image)\u003c/b\u003e as output \u003cb\u003eb\u003c/b\u003e. How will you do that?\u003c/p\u003e\u003cp\u003eExample: a=[1 3;4 2] and b=2;\u003c/p\u003e\u003cp\u003e\u003ca href = \"https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\"\u003ehttps://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003c/a\u003e\u003c/p\u003e","function_template":"function b=CountNearestDiagonalNonZeros(a)\r\nb=a+1;\r\nend","test_suite":"%%\r\na =magic(4);\r\nb_correct = 6;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =[-1 2 0 -6;0 1 2 -15;14 7 0 i;30 -1 0 -2];\r\nb_correct = 4;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =zeros(6);\r\nb_correct = 0;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n%%\r\na =[-4 -3 2 1;-9 0 0 1;1 5 -5 0;2 2 -1 4];\r\nb_correct =4;\r\nassert(isequal(CountNearestDiagonalNonZeros(a),b_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":430818,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":33,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-04-30T10:32:25.000Z","updated_at":"2026-03-31T12:56:36.000Z","published_at":"2020-04-30T10:54:12.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\u003eSuppose, you are being told to write a matrix,\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as input in MATLAB with having the possibility of containing zero and non-zero elements within a definite number of rows and columns. Furthermore, if you are told to\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\u003ecount only the total non-zero elements along the diagonals\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(Blue and Green mark on the attached image)\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\u003ethat are immediately next to the main diagonal\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e(Red mark on the attached image)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e as output\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e. How will you do that?\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: a=[1 3;4 2] and b=2;\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:hyperlink w:docLocation=\\\"https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026lt;https://drive.google.com/file/d/1vjx3D2cLbuq-gH2TC7XNYWMs3WSSObcb/view?usp=sharing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e\u0026gt;\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":960,"title":"Cell Source Index","description":"Suppose that C is a cell array whose elements consist of row vectors of elements of the same type.  For example, C could be a cell vector of strings:\r\n\r\n  C = {'abc' 'd' 'ef' 'ghij'};\r\n\r\nWe can put all the elements from all the vectors of C into a single vector:\r\n\r\n  VC = [C{:}];\r\n\r\nYour task:  write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came.  For example, if C has the value given above, then this would be the correct contents for iC:\r\n\r\n  iC = [1 1 1 2 3 3 4 4 4 4];\r\n\r\n","description_html":"\u003cp\u003eSuppose that C is a cell array whose elements consist of row vectors of elements of the same type.  For example, C could be a cell vector of strings:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eC = {'abc' 'd' 'ef' 'ghij'};\r\n\u003c/pre\u003e\u003cp\u003eWe can put all the elements from all the vectors of C into a single vector:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eVC = [C{:}];\r\n\u003c/pre\u003e\u003cp\u003eYour task:  write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came.  For example, if C has the value given above, then this would be the correct contents for iC:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eiC = [1 1 1 2 3 3 4 4 4 4];\r\n\u003c/pre\u003e","function_template":"function iC = cellSourceIndex(C)\r\n  iC = [];\r\nend","test_suite":"%%\r\nC = {'abc' 'd' 'ef' 'ghij'};\r\niC = [1 1 1 2 3 3 4 4 4 4];\r\nassert(isequal(cellSourceIndex(C),iC))\r\n\r\n%%\r\nC = {[1 2 3] [] 1 [] 2};\r\niC = [1 1 1 3 5];\r\nassert(isequal(cellSourceIndex(C),iC))\r\n\r\n%%\r\nassert(isequal(cellSourceIndex(num2cell(ones(3))),1:9))\r\n\r\n%%\r\nassert(isequal(cellSourceIndex({[] [] [] 1}),4))\r\n\r\n%%\r\nassert(isempty(cellSourceIndex({})))\r\n\r\n%%\r\nC = {struct('a',{1 2},'b',[]),struct('c',{1 2}),struct('d',{5 6 7 8})};\r\niC = [1 1 2 2 3 3 3 3];\r\nassert(isequal(cellSourceIndex(C),iC))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":3117,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":45,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-09-26T18:58:02.000Z","updated_at":"2026-03-31T10:53:41.000Z","published_at":"2012-09-26T18:58: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\u003eSuppose that C is a cell array whose elements consist of row vectors of elements of the same type. For example, C could be a cell vector of strings:\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 = {'abc' 'd' 'ef' 'ghij'};]]\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 can put all the elements from all the vectors of C into a single vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[VC = [C{:}];]]\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\u003eYour task: write a function that returns a vector iC, where each element of iC holds the index of the element of C from which the corresponding element of VC came. For example, if C has the value given above, then this would be the correct contents for iC:\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[iC = [1 1 1 2 3 3 4 4 4 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":1835,"title":"Matrix to column conversion","description":"Given a matrix of any size, convert it into a column vector.\r\ne.g A=[10 20 30;\r\n       40 50 60]\r\nthen,\r\nB = [10;\r\n    40;\r\n    20;\r\n    50;\r\n    30;\r\n    60;]","description_html":"\u003cp\u003eGiven a matrix of any size, convert it into a column vector.\r\ne.g A=[10 20 30;\r\n       40 50 60]\r\nthen,\r\nB = [10;\r\n    40;\r\n    20;\r\n    50;\r\n    30;\r\n    60;]\u003c/p\u003e","function_template":"function y = Mat2Vector(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [10 20 30;40 50 60];\r\ny_correct = [10; 40;20; 50; 30; 60;]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n\r\n%%\r\nx=[-2 -4 -6; -1 -3 -5; -10 -20 0]\r\ny_correct = [-2; -1;-10; -4; -3;-20; -6;-5;0]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n\r\n%%\r\nx=[1 2 3 4 5; 6 7 8 9 10];\r\nx(:,:,2) = [10 20 30 40 50;60 70 80 90 100];\r\ny_correct = [1;6;2;7;3;8;4;9;5;10;10;60;20;70;30;80;40;90;50;100]\r\nassert(isequal(Mat2Vector(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":372,"test_suite_updated_at":"2013-08-18T20:55:54.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-08-18T20:39:50.000Z","updated_at":"2026-02-18T14:49:11.000Z","published_at":"2013-08-18T20:40:16.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix of any size, convert it into a column vector. e.g A=[10 20 30; 40 50 60] then, B = [10; 40; 20; 50; 30; 60;]\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":61021,"title":"The Case of the Missing Prototype – Check the Lab’s Logbook for Suspicious Late-Night Entries","description":"After counting the fingerprints, you turn your attention to the security logbook.It records the entry hours (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, no one is allowed inside after 9 PM (21 hours).Every suspicious late-night entry could reveal a key suspect!\r\nYour task is to determine how many entries occurred during these restricted hours.\r\nGiven a numeric vector entries, return the number of times people entered the lab at or after 21.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 123px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 61.5px; transform-origin: 408px 61.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: 385px 31.5px; text-align: left; transform-origin: 385px 31.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eAfter counting the fingerprints, you turn your attention to the security logbook.It records the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eentry hours\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eno one is allowed inside after 9 PM (21 hours)\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.Every suspicious late-night entry could reveal a key suspect!\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour task is to determine how many entries occurred during these restricted hours.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a numeric vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eentries\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, return the number of times people entered the lab at or after 21.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function count = suspiciousEntries(entries)\r\n  y = x;\r\nend","test_suite":"%%\r\nentries = [8 10 21 22 23 17 14];\r\nentries_correct = 3;\r\nassert(isequal(suspiciousEntries(entries),entries_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":4953963,"edited_at":"2025-10-20T15:46:05.000Z","deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2025-10-20T15:46:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T15:43:22.000Z","updated_at":"2026-04-03T03:47:52.000Z","published_at":"2025-10-20T15:46:05.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\u003eAfter counting the fingerprints, you turn your attention to the security logbook.It records the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eentry hours\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e (from 0 to 23) of everyone who accessed the Innovation Lab.As per lab policy, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eno one is allowed inside after 9 PM (21 hours)\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.Every suspicious late-night entry could reveal a key suspect!\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\u003eYour task is to determine how many entries occurred during these restricted hours.\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\u003eGiven a numeric vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eentries\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, return the number of times people entered the lab at or after 21.\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":647,"title":"Getting the absolute index from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix row and column index from a matrix\u003e, and the \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexing\u003e technique but there is another way to reference specific elements in a matrix.\r\n\r\nAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\r\n\r\n\u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Indexing into a vector\u003e is really using this kind of indexing, but it is more natural feeling.\r\n\r\nUse \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e.\r\n\r\nGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector Binary comparison\u003e to satisfy two conditions)","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\"\u003erow and column index from a matrix\u003c/a\u003e, and the \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexing\u003c/a\u003e technique but there is another way to reference specific elements in a matrix.\u003c/p\u003e\u003cp\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column).  The upper left entry is value 1, the lower right is the highest value.  MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\u003c/p\u003e\u003cp\u003e\u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eIndexing into a vector\u003c/a\u003e is really using this kind of indexing, but it is more natural feeling.\u003c/p\u003e\u003cp\u003eUse \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound).  (See \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003eBinary comparison\u003c/a\u003e to satisfy two conditions)\u003c/p\u003e","function_template":"function AI = absoluteInBetween(M, LB, UB)\r\n  AI = 1;\r\nend","test_suite":"%%\r\nM = magic(5)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))\r\n\r\n%%\r\nM = magic(10)\r\nLB = 3;\r\nUB = 10;\r\n\r\nAI = find((M \u003e LB) \u0026 (M \u003c UB));\r\n\r\nassert(isequal(absoluteInBetween(M, LB, UB),AI))","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":257,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:39:39.000Z","updated_at":"2026-03-29T19:40:43.000Z","published_at":"2012-05-01T15:39:39.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eYou may already know how to get the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/646-getting-the-row-and-column-location-from-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003erow and column index from a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, and the\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexing\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e technique but there is another way to reference specific elements 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\u003eAbsolute indexing refers to specific elements with a single scalar rather than two (row and column). The upper left entry is value 1, the lower right is the highest value. MATLAB is column major, so you count down the rows in a specific column first, moving right as needed until you reach the end.\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:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eIndexing into a vector\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e is really using this kind of indexing, but it is more natural feeling.\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\u003eUse\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix M, return the absolute indices where M is greater than scalar, LB (Lower Bound) and less than UB (Upper Bound). (See\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/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eBinary comparison\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to satisfy two conditions)\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":646,"title":"Getting the row and column location from a matrix","description":"This is a basic MATLAB operation. It is for instructional purposes.\r\n\r\n---\r\n\r\nYou may already know how to get \u003chttp://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector logical indexes\u003e from a vector, and to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector find the location\u003e of elements in a vector.\r\n\r\nWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\r\n\r\n   [0 1 0\r\n    0 0 0]\r\n\r\nYou might want \r\n\r\n  row = 1\r\n  col = 2\r\n\r\nor \r\n\r\n   [0 1 1\r\n    1 0 0]\r\n\r\n   row = [2\r\n          1\r\n          1]\r\n\r\n   col = [1\r\n          2\r\n          3]\r\n\r\nCheck out \u003chttp://www.mathworks.com/help/techdoc/ref/find.html Find\u003e to learn to do this.\r\n\r\nGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.","description_html":"\u003cp\u003eThis is a basic MATLAB operation. It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eYou may already know how to get \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/640-do-a-binary-comparison-on-a-vector\"\u003elogical indexes\u003c/a\u003e from a vector, and to \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003efind the location\u003c/a\u003e of elements in a vector.\u003c/p\u003e\u003cp\u003eWhat if you are dealing with a matrix.  Often you will want the row and column location of an element, or set of elements.  For instance:\u003c/p\u003e\u003cpre\u003e   [0 1 0\r\n    0 0 0]\u003c/pre\u003e\u003cp\u003eYou might want\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003erow = 1\r\ncol = 2\r\n\u003c/pre\u003e\u003cp\u003eor\u003c/p\u003e\u003cpre\u003e   [0 1 1\r\n    1 0 0]\u003c/pre\u003e\u003cpre\u003e   row = [2\r\n          1\r\n          1]\u003c/pre\u003e\u003cpre\u003e   col = [1\r\n          2\r\n          3]\u003c/pre\u003e\u003cp\u003eCheck out \u003ca href=\"http://www.mathworks.com/help/techdoc/ref/find.html\"\u003eFind\u003c/a\u003e to learn to do this.\u003c/p\u003e\u003cp\u003eGiven a matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh.  R and C will be combined into matrix out.\u003c/p\u003e","function_template":"function out = RCgreaterThan(M, thresh)\r\n  r = 1;\r\n  c = 1;\r\n  out = [r c]; %only one output can be checked in Cody!\r\nend","test_suite":"%%\r\nM = magic(5);\r\nthresh = 4;\r\n\r\n[r,c]= find(magic(5) \u003e 4)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))\r\n\r\n%%\r\nM = magic(6);\r\nthresh = 2;\r\n\r\n[r,c]= find(magic(6) \u003e 2)\r\nout = [r c]\r\n\r\nassert(isequal(RCgreaterThan(M, thresh),out))","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":299,"test_suite_updated_at":"2012-05-01T15:24:26.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-05-01T15:19:06.000Z","updated_at":"2026-03-09T20:35:23.000Z","published_at":"2012-05-01T15:24:26.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eYou may already know how to get\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/640-do-a-binary-comparison-on-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003elogical indexes\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e from a vector, and to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003efind the location\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e of elements in a vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhat if you are dealing with a matrix. Often you will want the row and column location of an element, or set of elements. For instance:\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[   [0 1 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\u003eYou might want\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[row = 1\\ncol = 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\u003eor\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[   [0 1 1\\n    1 0 0]\\n\\n   row = [2\\n          1\\n          1]\\n\\n   col = [1\\n          2\\n          3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eCheck out\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/techdoc/ref/find.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eFind\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e to learn to do this.\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 matrix, M, return the column vectors that represent the row and column indices, r and c, where the given matrix, M is greater than the threshold value, thresh. R and C will be combined into matrix out.\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":105,"title":"How to find the position of an element in a vector without using the find function","description":"Write a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\r\n\r\nExamples:\r\n\r\n findPosition([1 3 5 4 2], 2)\r\n posX is 5\r\n\r\n findPosition([1 5 8 6 7 6 0], 8)\r\n posX is 3","description_html":"\u003cp\u003eWrite a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\u003c/p\u003e\u003cp\u003eExamples:\u003c/p\u003e\u003cpre\u003e findPosition([1 3 5 4 2], 2)\r\n posX is 5\u003c/pre\u003e\u003cpre\u003e findPosition([1 5 8 6 7 6 0], 8)\r\n posX is 3\u003c/pre\u003e","function_template":"function posX = findPosition(x,y)\r\n  posX = 0;\r\nend","test_suite":"%%\r\nx = [1 3 5 4 2];\r\ny = 2\r\nposX_correct = 5;\r\nassert(isequal(findPosition(x,y),posX_correct))\r\n\r\n\r\n%%\r\nx = [1 5 8 6 7 6 0];\r\ny = 8\r\nposX_correct = 3;\r\nassert(isequal(findPosition(x,y),posX_correct))\r\n","published":true,"deleted":false,"likes_count":14,"comments_count":8,"created_by":139,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":2815,"test_suite_updated_at":"2012-01-26T23:03:50.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2012-01-26T00:51:27.000Z","updated_at":"2026-04-03T07:03:22.000Z","published_at":"2012-01-26T23:18:05.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\u003eWrite a function posX=findPosition(x,y) where x is a vector and y is the number that you are searching for.\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\u003eExamples:\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[ findPosition([1 3 5 4 2], 2)\\n posX is 5\\n\\n findPosition([1 5 8 6 7 6 0], 8)\\n posX is 3]]\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":54705,"title":"Draw a Diamond shape in ones Matrix with '0' s","description":"Input will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\r\ny =\r\n\r\n     1     0     1\r\n     0     1     0\r\n     1     0     1\r\n\r\n\r\n","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 282px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 141px; transform-origin: 407px 141px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eInput will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003ey =\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     1     0     1\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     0     1     0\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e     1     0     1\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1;0 1 0;1 0 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 5;\r\ny_correct = [1 1 0 1 1;1 0 1 0 1;0 1 1 1 0;1 0 1 0 1;1 1 0 1 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx=7;\r\ny_correct = [ 1 1 1 0 1 1 1;1 1 0 1 0 1 1;1 0 1 1 1 0 1;0 1 1 1 1 1 0;1 0 1 1 1 0 1;1 1 0 1 0 1 1;1 1 1 0 1 1 1]\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":2061009,"edited_by":2061009,"edited_at":"2022-06-04T06:51:32.000Z","deleted_by":null,"deleted_at":null,"solvers_count":28,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-06-04T06:50:43.000Z","updated_at":"2026-03-24T13:37:47.000Z","published_at":"2022-06-04T06:51:32.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\u003eInput will be odd numbers.The task is to make a Diamond shape in a ones matrix with '0's where the matrix will be a square matrix of length and width equal to the input. For Example, Input x=3, output will be:\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\u003ey =\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\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\u003e     1     0     1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e     0     1     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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e     1     0     1\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\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\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":1951,"title":"Better Index Number ","description":"Let's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\r\n\r\n    file1\r\n    file101\r\n    file2\r\n    etc.\r\n\r\nWhich is not ideal when you want your files to go like this:\r\n\r\n    file1\r\n    file2\r\n    file101\r\n    etc.\r\n\r\nSo let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file. ","description_html":"\u003cp\u003eLet's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\u003c/p\u003e\u003cpre\u003e    file1\r\n    file101\r\n    file2\r\n    etc.\u003c/pre\u003e\u003cp\u003eWhich is not ideal when you want your files to go like this:\u003c/p\u003e\u003cpre\u003e    file1\r\n    file2\r\n    file101\r\n    etc.\u003c/pre\u003e\u003cp\u003eSo let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file.\u003c/p\u003e","function_template":"function n_str = betterIndexNum(n,max_n)\r\n  n_str = str(n);\r\nend","test_suite":"%%\r\nn = 1;\r\nmax_n = 9;\r\nn_str = '1';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 1;\r\nmax_n = 28;\r\nn_str = '01';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 28;\r\nmax_n = 848984;\r\nn_str = '000028';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))\r\n\r\n%%\r\nn = 10;\r\nmax_n = 100;\r\nn_str = '010';\r\nassert(isequal(betterIndexNum(n,max_n),n_str))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":3743,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":92,"test_suite_updated_at":"2013-10-24T06:58:01.000Z","rescore_all_solutions":false,"group_id":673,"created_at":"2013-10-20T07:52:06.000Z","updated_at":"2026-02-26T15:47:19.000Z","published_at":"2013-10-20T08:03:17.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\u003eLet's say you want to save many, many files and append these files with a certain sortable index number. As you probably know, you often get in a situation where your files go like this:\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[    file1\\n    file101\\n    file2\\n    etc.]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eWhich is not ideal when you want your files to go like this:\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[    file1\\n    file2\\n    file101\\n    etc.]]\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 let's make a function that given the current index number and the maximum index number, it will return a string with leading 0's so that any computer will know how to sort the files. For example, if I were on index 9 and there were a total of 230 files, my function would return '009' so I could append that to my file.\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":47508,"title":"Convert sorting indices to ranks","description":null,"description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 93px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 46.5px; transform-origin: 407px 46.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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eThe second output of sort() is the sorting index vector, telling where the corresponding element in the sorted vector was in the raw vector. However sometimes we want to know where the elements of the raw vector goes into the sorted vector, i.e., ranks.\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eCan you find the shortest solution?\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function Ranks = SortingIndices2Ranks(SortingIndices)\r\n  Ranks=SortingIndices;\r\nend","test_suite":"%%\r\nRawVector=rand(10,1);\r\n[SortedVector,SortingIndices]=sort(RawVector);\r\nRanks=SortingIndices2Ranks(SortingIndices);\r\nassert(isequal(SortedVector(Ranks),RawVector));","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":362068,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":13,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-11-15T04:05:17.000Z","updated_at":"2025-11-28T17:59:25.000Z","published_at":"2020-11-15T04:05:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe second output of sort() is the sorting index vector, telling where the corresponding element in the sorted vector was in the raw vector. However sometimes we want to know where the elements of the raw vector goes into the sorted vector, i.e., ranks.\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\u003eCan you find the shortest solution?\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":1368,"title":"Create an 8-color version of an image","description":"This problem was inspired by a tweet I saw from @MATLAB regarding \u003chttp://www.mathworks.com/matlabcentral/fileexchange/37816-the-warholer?s_eid=PSM_3808 The Warholer\u003e.\r\n\r\nGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \"image\" will only have 8 colors.\r\n\r\nYou may assume that the inputs are on the interval [0,255].\r\n\r\n\r\n\r\n","description_html":"\u003cp\u003eThis problem was inspired by a tweet I saw from @MATLAB regarding \u003ca href = \"http://www.mathworks.com/matlabcentral/fileexchange/37816-the-warholer?s_eid=PSM_3808\"\u003eThe Warholer\u003c/a\u003e.\u003c/p\u003e\u003cp\u003eGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \"image\" will only have 8 colors.\u003c/p\u003e\u003cp\u003eYou may assume that the inputs are on the interval [0,255].\u003c/p\u003e","function_template":"function B = warholer(A,t)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = randi([51 255],[600 800 3]);\r\nt = [0 25 50];\r\nB = warholer(A,t);\r\nassert(all(B(:)==255))\r\n\r\n%%\r\nA = randi(100,[800 600 3]);\r\nt = [100 255 100];\r\nB = warholer(A,t);\r\nassert(all(B(:)==0))\r\n\r\n%%\r\nA = zeros(200,200,3);\r\nt = randi(255,1,3);\r\nB = warholer(A,t);\r\nassert(all(B(:)==0))\r\n\r\n%%\r\nA = 255*ones(100,100,3);\r\nt = randi(254,1,3);\r\nB = warholer(A,t);\r\nassert(all(B(:)==255))\r\n\r\n%%\r\nA(:,:,1) = randi([0 120],[480 320]);\r\nA(:,:,2) = randi([80 200],[480 320]);\r\nA(:,:,3) = randi([160 240],[480 320]);\r\nt = [150 50 150];\r\nB = warholer(A,t);\r\nassert(all(all(B(:,:,1)==0)))\r\nassert(all(all(B(:,:,2)==255)))\r\nassert(all(all(B(:,:,3)==255)))\r\n\r\n%%\r\nA(:,:,1) = randi([0 100],[480 320]);\r\nA(:,:,2) = randi([80 180],[480 320]);\r\nA(:,:,3) = randi([100 240],[480 320]);\r\nt = [180 60 250];\r\nB = warholer(A,t);\r\nassert(all(all(B(:,:,1)==0)))\r\nassert(all(all(B(:,:,2)==255)))\r\nassert(all(all(B(:,:,3)==0)))\r\n\r\n%%\r\nA(:,:,1) = magic(5)*10;\r\nA(:,:,2) = spiral(5)*10;\r\nA(:,:,3) = toeplitz(1:5)*50;\r\nt = [159 99 149];\r\nB_correct(:,:,1) = [255 255 0   0   0;\r\n                    255 0   0   0   255;\r\n                    0   0   0   255 255;\r\n                    0   0   255 255 0;\r\n                    0   255 255 0   0];\r\nB_correct(:,:,2) = [255 255 255 255 255;\r\n                    255 0   0   0   255;\r\n                    255 0   0   0   255;\r\n                    255 0   0   0   255;\r\n                    255 255 255 255 255];\r\nB_correct(:,:,3) = [0   0   255 255 255;\r\n                    0   0   0   255 255;\r\n                    255 0   0   0   255;\r\n                    255 255 0   0   0;\r\n                    255 255 255 0   0];\r\nassert(isequal(warholer(A,t),B_correct))\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":62,"test_suite_updated_at":"2013-08-05T02:37:21.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-03-20T23:26:39.000Z","updated_at":"2026-03-31T14:55:47.000Z","published_at":"2013-08-05T02:37:21.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 was inspired by a tweet I saw from @MATLAB regarding\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/fileexchange/37816-the-warholer?s_eid=PSM_3808\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eThe Warholer\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an MxNx3 array (A) representing an image and a threshold for each channel (r/g/b), generate a new array (B) whose elements are 255 if greater than the threshold for that channel or 0 otherwise. This means the new \\\"image\\\" will only have 8 colors.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou may assume that the inputs are on the interval [0,255].\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":61032,"title":"The MATLAB Treasure Hunt – Count Matching Symbols on the Ancient Scroll to Unlock the Next Clue","description":"Inside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\r\nA note beside it says: “Count those that mirror the key symbol — they guide your way.”\r\nGiven a character array or string s and a single character key, count how many times key appears in s.\r\nReturn this count as n.\r\nEach correct count reveals one rune on the treasure map!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 70.5px; transform-origin: 408px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eInside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eA note beside it says: \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e“Count those that mirror the key symbol — they guide your way.”\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a character array or string \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and a single character \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ekey\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, count how many times \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ekey\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e appears in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn this count as \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003en\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEach correct count reveals one rune on the treasure map!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = countSymbols(s,key)\r\n  y = x;\r\nend","test_suite":"%%\r\ns = 'x#x@xx@#x';\r\nkey = 'x';\r\ny_correct = 5;\r\nassert(isequal(countSymbols(s,key),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":87,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-21T09:27:12.000Z","updated_at":"2026-03-10T12:41:25.000Z","published_at":"2025-10-21T09:27:12.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\u003eInside the Hidden Cave, you discover an ancient scroll filled with strange symbols and markings.\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 note beside it says: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e“Count those that mirror the key symbol — they guide your way.”\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a character array or string \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and a single character \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ekey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, count how many times \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ekey\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e appears in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eReturn this count as \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEach correct count reveals one rune on the treasure map!\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":53950,"title":"Time reverse indices","description":"Time reverse the index values as follows\r\nIndexIn = [7 1 0]    \r\nIndexOut = [7 6 0]\r\nNote that the indices are zero based and sorted from largest to smallest.\r\nYou can think of this as a time reversal of a vector:\r\n[7 1 0] --\u003e [1     1     0     0     0     0     0     1 ] \r\n[7 6 0] --\u003e [1     0     0     0     0     0     1     1 ]\r\n\r\nHere is a second example\r\n[8 4 3 2 0]  --\u003e [ 1     0     1     1     1     0     0     0     1 ]\r\n[8 6 5 4 0]  --\u003e [ 1     0     0     0     1     1     1     0     1 ]\r\n\r\nBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 465px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 331.5px 232.5px; transform-origin: 331.5px 232.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eTime reverse the index values as follows\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIndexIn = [7 1 0]    \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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eIndexOut = [7 6 0]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eNote that the indices are zero based and sorted from largest to smallest.\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eYou can think of this as a time reversal of a vector:\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[7 1 0] --\u0026gt; [1     1     0     0     0     0     0     1 ] \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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[7 6 0] --\u0026gt; [1     0     0     0     0     0     1     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eHere is a second example\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[8 4 3 2 0]  --\u0026gt; [ 1     0     1     1     1     0     0     0     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e[8 6 5 4 0]  --\u0026gt; [ 1     0     0     0     1     1     1     0     1 ]\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: 308.5px 10.5px; text-align: left; transform-origin: 308.5px 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 105px; 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: 308.5px 52.5px; text-align: left; transform-origin: 308.5px 52.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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function IndexOut = reverseIndices(IndexIn)\r\n  IndexOut = IndexIn;\r\nend","test_suite":"%%\r\nx = [7  1  0];\r\ny_correct = [7  6  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [8  4  3  2  0];\r\ny_correct = [8  6  5  4  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [9  4  0];\r\ny_correct = [9  5  0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [10   3   0];\r\ny_correct = [10   7   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [11   2   0];\r\ny_correct = [11   9   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [45   4   3   1   0];\r\ny_correct = [45  44  42  41   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [46   8   5   3   2   1   0];\r\ny_correct = [46  45  44  43  41  38   0];\r\nassert(isequal(reverseIndices(x),y_correct))\r\n%%\r\nx = [47   5   0];\r\ny_correct = [47  42   0];\r\nassert(isequal(reverseIndices(x),y_correct))","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":280816,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-01-20T21:14:20.000Z","updated_at":"2025-07-13T09:05:06.000Z","published_at":"2022-01-20T21:14:20.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTime reverse the index values as follows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIndexIn = [7 1 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIndexOut = [7 6 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNote that the indices are zero based and sorted from largest to smallest.\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\u003eYou can think of this as a time reversal of a vector:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[7 1 0] --\u0026gt; [1     1     0     0     0     0     0     1 ] \u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[7 6 0] --\u0026gt; [1     0     0     0     0     0     1     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eHere is a second example\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\u003e[8 4 3 2 0]  --\u0026gt; [ 1     0     1     1     1     0     0     0     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e[8 6 5 4 0]  --\u0026gt; [ 1     0     0     0     1     1     1     0     1 ]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\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\u003eBackground of problem.  The index defines the tap positions (or characteristic polynomial) of a Linear Feedback Shift Register (LFSR).  When the polynomial is primitive, the LFSR goes through all possible states before repeating, thus creating a psuedo random binary sequence (PRBS). A curious property is that if the tap positions are reversed, as we are doing in this problem, then the output sequence is also reversed.\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":640,"title":"Getting logical indexes","description":"This is a basic MATLAB operation.  It is for instructional purposes.\r\n\r\n---\r\n\r\nLogical indexing works like this.\r\n\r\n  thresh = 4;\r\n  vec    = [1 2 3 4 5 6 7 8];\r\n  \r\n  vi     = (vec \u003e thresh)\r\n  \r\n  vi =\r\n  \r\n       0     0     0     0     1     1     1     1\r\n\r\nOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\r\n\r\nIt can be used to get the values out:\r\n\r\n  big = vec(vi)\r\n  \r\n  big =\r\n  \r\n       5     6     7     8\r\n\r\nGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\r\n\r\nNote, this works just as well with scalars and matrices.\r\n\r\n----\r\n\r\nTo get the indices where this comparison is true, see this \u003chttp://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector Cody problem\u003e.","description_html":"\u003cp\u003eThis is a basic MATLAB operation.  It is for instructional purposes.\u003c/p\u003e\u003cp\u003e---\u003c/p\u003e\u003cp\u003eLogical indexing works like this.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ethresh = 4;\r\nvec    = [1 2 3 4 5 6 7 8];\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi     = (vec \u003e thresh)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003evi =\r\n\u003c/pre\u003e\u003cpre\u003e       0     0     0     0     1     1     1     1\u003c/pre\u003e\u003cp\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\u003c/p\u003e\u003cp\u003eIt can be used to get the values out:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ebig = vec(vi)\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ebig =\r\n\u003c/pre\u003e\u003cpre\u003e       5     6     7     8\u003c/pre\u003e\u003cp\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\u003c/p\u003e\u003cp\u003eNote, this works just as well with scalars and matrices.\u003c/p\u003e\u003cp\u003e----\u003c/p\u003e\u003cp\u003eTo get the indices where this comparison is true, see this \u003ca href=\"http://www.mathworks.com/matlabcentral/cody/problems/645-getting-the-indices-from-a-vector\"\u003eCody problem\u003c/a\u003e.\u003c/p\u003e","function_template":"function vi = binaryEqualsVector(vec, v)\r\n  vi = true;\r\nend","test_suite":"%%\r\nvec = [1 2 3 3 2 1];\r\nv = 2;\r\ny_correct = [false true false false true false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 2 3 4 5 6];\r\nv = 0;\r\ny_correct = [false false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = [1 1 1 1 1];\r\nv = 1;\r\ny_correct = [true true true true true];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n\r\n%%\r\nvec = 'abcdef';\r\nv = 'a';\r\ny_correct = [true false false false false false];\r\nassert(isequal(binaryEqualsVector(vec,v),y_correct))\r\n","published":true,"deleted":false,"likes_count":9,"comments_count":0,"created_by":240,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1182,"test_suite_updated_at":"2012-04-30T18:48:13.000Z","rescore_all_solutions":false,"group_id":12,"created_at":"2012-04-30T18:46:03.000Z","updated_at":"2026-02-10T12:14:38.000Z","published_at":"2012-04-30T18:48:13.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 a basic MATLAB operation. It is for instructional purposes.\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\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\u003eLogical indexing works like this.\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[thresh = 4;\\nvec    = [1 2 3 4 5 6 7 8];\\n\\nvi     = (vec \u003e thresh)\\n\\nvi =\\n\\n       0     0     0     0     1     1     1     1]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eOnce you have this TRUE FALSE vector (I call it vi: Valid Indices)\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 can be used to get the values out:\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[big = vec(vi)\\n\\nbig =\\n\\n       5     6     7     8]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a vector, vec, and a value, v, return a binary vector that represents the indices where vector, vec, is equal to scalar, v.\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 works just as well with scalars and matrices.\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\u003e----\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eTo get the indices where this comparison is true, see this\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/645-getting-the-indices-from-a-vector\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCody problem\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":1786,"title":"Create an index-powered vector","description":"Given a input vector x, return y as index-powered vector as shown below.\r\n\r\nExample\r\n\r\n x = [2 3 6 9]\r\n\r\nthen y should be \r\n\r\n [2^1 3^2 6^3 9^4] = [2 9 216 6561]\r\n","description_html":"\u003cp\u003eGiven a input vector x, return y as index-powered vector as shown below.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x = [2 3 6 9]\u003c/pre\u003e\u003cp\u003ethen y should be\u003c/p\u003e\u003cpre\u003e [2^1 3^2 6^3 9^4] = [2 9 216 6561]\u003c/pre\u003e","function_template":"function y = index_power(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [2 3 6 9];\r\ny_correct = [2 9 216 6561];\r\nassert(isequal(index_power(x),y_correct))\r\n\r\n%%\r\nx = [1 5 11 0 -3 -6];\r\ny_correct = [1  25 1331 0 -243 46656];\r\nassert(isequal(index_power(x),y_correct))\r\n\r\n%%\r\nx = [0 8 -12 0 -8 -2];\r\ny_correct = [0 64 -1728 0 -32768 64];\r\nassert(isequal(index_power(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":941,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":13,"created_at":"2013-08-12T02:52:55.000Z","updated_at":"2026-03-31T02:56:27.000Z","published_at":"2013-08-12T02:54:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a input vector x, return y as index-powered vector as shown below.\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 6 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 y should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [2^1 3^2 6^3 9^4] = [2 9 216 6561]]]\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":2012,"title":"Tony's trick for duplicating an mx1 vector n times","description":"Without using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 0.\r\n\r\nExamples\r\n\r\nIf\r\n\r\n v = 5;\r\n n = 3;\r\n\r\nthen return v1:\r\n\r\n v1 = [5 5 5] \r\n\r\nIf a 2d matrix is supplied then the vector v will be the first column.\r\n\r\n V = magic(4);\r\n n = 4;\r\n\r\nthen v and v1 are returned as shown below.\r\n\r\n v = [16 5 9 4]'\r\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 4] \r\n\r\nHint: use indexing\r\n","description_html":"\u003cp\u003eWithout using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 0.\u003c/p\u003e\u003cp\u003eExamples\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre\u003e v = 5;\r\n n = 3;\u003c/pre\u003e\u003cp\u003ethen return v1:\u003c/p\u003e\u003cpre\u003e v1 = [5 5 5] \u003c/pre\u003e\u003cp\u003eIf a 2d matrix is supplied then the vector v will be the first column.\u003c/p\u003e\u003cpre\u003e V = magic(4);\r\n n = 4;\u003c/pre\u003e\u003cp\u003ethen v and v1 are returned as shown below.\u003c/p\u003e\u003cpre\u003e v = [16 5 9 4]'\r\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 4] \u003c/pre\u003e\u003cp\u003eHint: use indexing\u003c/p\u003e","function_template":"function v1 = reproduce_nv(v,n)\r\n  v1 = v;\r\nend","test_suite":"%%\r\nx=magic(3);\r\nn=3;\r\ny_correct=[8 8 8; 3 3 3; 4 4 4];\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%%\r\nx=magic(10);\r\nn=19;\r\ny_correct=repmat(x(:,1),1,19);\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%% \r\nx=1;\r\nn=0;\r\ny_correct=linspace(x,x,n); %arbitrary way to get the soln\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n%%\r\nx='1';\r\nn=7;\r\ny_correct=['1' '1' '1' '1' '1' '1' '1'];\r\nassert(isequal(reproduce_nv(x,n),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":2,"created_by":17471,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":58,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-11-23T08:42:47.000Z","updated_at":"2026-04-02T12:30:19.000Z","published_at":"2013-11-23T08:48:28.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\u003eWithout using repmat, or for loop, or concatenation, create a function to duplicate a vector, v, a specified number of times, n. v can be numeric or character. n may be 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\u003eExamples\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\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[ v = 5;\\n n = 3;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen return v1:\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[ v1 = [5 5 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\u003eIf a 2d matrix is supplied then the vector v will be the first column.\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[ V = magic(4);\\n n = 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\u003ethen v and v1 are returned as shown below.\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[ v = [16 5 9 4]'\\n v1 = [16 16 16 16; 5 5 5 5; 9 9 9 9; 4 4 4 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\u003eHint: use indexing\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":56453,"title":"Multiply each matrix element by its row index and add its column index.","description":"Return a matrix the same size as the input, multiply each element by its row index and add its column index.\r\nExample:\r\nx = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]\r\nshould return\r\ny = [ 2 4 6 ; 9 12 15; 22 26 30 ]","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: 141px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 70.5px; transform-origin: 407px 70.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 334.125px 7.91667px; transform-origin: 334.125px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a matrix the same size as the input, multiply each element by its row index and add its column index.\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: 29.175px 7.91667px; transform-origin: 29.175px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eExample:\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: 77.5667px 7.91667px; transform-origin: 77.5667px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ex = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]\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: 40.85px 7.91667px; transform-origin: 40.85px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eshould return\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: 95.0833px 7.91667px; transform-origin: 95.0833px 7.91667px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ey = [ 2 4 6 ; 9 12 15; 22 26 30 ]\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = MultRowAddCol(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1;\r\ny_correct = 2;\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = [ 1 2 3 ; 4 5 6 ; 7 8 9 ];\r\ny_correct = [ 2 4 6 ; 9 12 15; 22 26 30 ];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = [101:110;111:120;121:130];\r\ny_correct = [102:2:120;223:3:250;364:4:400];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx = reshape(-40:2:-2,4,5);\r\nx(1) = Inf;\r\ny_correct = [Inf -30 -21 -12 -3;-75 -58 -41 -24 -7;-107 -82 -57 -32 -7;-135 -102 -69 -36 -3];\r\nassert(isequal(MultRowAddCol(x),y_correct))\r\n%%\r\nx=[];\r\nassert(isempty(MultRowAddCol(x)));\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":2414210,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":19,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-11-04T18:36:47.000Z","updated_at":"2026-03-27T16:46:15.000Z","published_at":"2022-11-04T18:36: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\u003eReturn a matrix the same size as the input, multiply each element by its row index and add its column index.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex = [ 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\u003eshould return\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\u003ey = [ 2 4 6 ; 9 12 15; 22 26 30 ]\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":44797,"title":"Cannibal eating odd and even numbered men","description":"There are N men in a queue.  A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time.  In the first round he eats all the odd-numbered.  In the next round he eats all even-numbered.  This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? \r\ne.g. If N = 6,\r\n\r\nMen remaining after round 1: 2, 4, 6\r\n\r\nMen remaining after round 2: 2, 6\r\n\r\nMen remaining after round 3: 6\r\n\r\nHence answer = 6\r\n","description_html":"\u003cp\u003eThere are N men in a queue.  A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time.  In the first round he eats all the odd-numbered.  In the next round he eats all even-numbered.  This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? \r\ne.g. If N = 6,\u003c/p\u003e\u003cp\u003eMen remaining after round 1: 2, 4, 6\u003c/p\u003e\u003cp\u003eMen remaining after round 2: 2, 6\u003c/p\u003e\u003cp\u003eMen remaining after round 3: 6\u003c/p\u003e\u003cp\u003eHence answer = 6\u003c/p\u003e","function_template":"function y = survivor_odds(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1000;\r\ny_correct = 342;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n%%\r\nx = 2000;\r\ny_correct = 1366;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n%%\r\nx = 10000;\r\ny_correct = 5462;\r\nassert(isequal(survivor_odds(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":107204,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":31,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-11-29T07:49:28.000Z","updated_at":"2025-12-07T16:57:25.000Z","published_at":"2018-11-29T07:49:32.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\u003eThere are N men in a queue. A cannibal eats either all odd-numbered or all even-numbered men in the queue at a time. In the first round he eats all the odd-numbered. In the next round he eats all even-numbered. This goes on repeating (with odd or even toggling after every round) till there is only 1 man in the queue. What would be the original number of this man in the queue? e.g. If N = 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 1: 2, 4, 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 2: 2, 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMen remaining after round 3: 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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHence answer = 6\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":44496,"title":"vector indexes for a matrix","description":"Matlab allows us to use several indexing styles making code simpler and easier to read than using loops. \r\n\r\nVectors can have vector subscripts\r\n\r\n  V = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n     2     4     6\r\n\r\nIn case of matrices, it allows us to use linear indexing.\r\n \r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n     2     4     6\r\n\r\n\r\nGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops. \r\n\r\nFor example (tl;dr)\r\n\r\n  M = [2 5 8;\r\n       3 6 9; \r\n       4 7 10];\r\n  P = [1 1 2]; Q = [1 3 2];\r\n  Matrix_VectorIndexes(M,P,Q)\r\n  ans =\r\n     2     4     6\r\n\r\n","description_html":"\u003cp\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\u003c/p\u003e\u003cp\u003eVectors can have vector subscripts\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eV = [2 3 4 5 6 7 8 9 10];\r\nidx = [1 3 5];\r\nV(idx)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eIn case of matrices, it allows us to use linear indexing.\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nidx = [1 3 5];\r\nM(idx) \r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e\u003cp\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\u003c/p\u003e\u003cp\u003eFor example (tl;dr)\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 1 2]; Q = [1 3 2];\r\nMatrix_VectorIndexes(M,P,Q)\r\nans =\r\n   2     4     6\r\n\u003c/pre\u003e","function_template":"function y = Matrix_VectorIndexes(M,P,Q)\r\n  y = M(P,Q);  %M(P,Q) gives wrong answer because matlab reads it as linear indexing of matrices \r\n               % M(1,1) is not considered linear indexing, but M([1,1]),M([1],[1]) etc., is \r\nend","test_suite":"%%\r\nM = [1 2 3;\r\n     4 5 6;\r\n     7 8 9];\r\nP = [1 2 3]; Q= [1 2 3];\r\ny_correct = [1,5,9];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [2 5 8;\r\n     3 6 9; \r\n     4 7 10];\r\nP = [1 3 2]; Q = [1 1 2];\r\ny_correct = [2,4,6];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = 1:3; Q = 3:-1:1;\r\ny_correct = [4,9,8];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4;\r\n     7 9 6; \r\n     8 2 3];\r\nP = reshape(repmat((1:3)',[1,3]),[1,9]);\r\nQ = reshape(repmat(1:3,[3,1]),[1,9]);\r\ny_correct = M(:)';\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n\r\n%%\r\nM = [1 5 4 2;\r\n     7 9 6 1; \r\n     8 2 3 5];\r\nP = [2,1,3,2]; Q = 1:4;\r\ny_correct = [7,5,3,1];\r\nassert(isequal(Matrix_VectorIndexes(M,P,Q),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":162999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":36,"test_suite_updated_at":"2018-06-16T21:47:05.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2018-01-10T07:13:18.000Z","updated_at":"2026-04-02T13:18:07.000Z","published_at":"2018-01-10T07:33:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMatlab allows us to use several indexing styles making code simpler and easier to read than using loops.\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\u003eVectors can have vector subscripts\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[V = [2 3 4 5 6 7 8 9 10];\\nidx = [1 3 5];\\nV(idx)\\nans =\\n   2     4     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\u003eIn case of matrices, it allows us to use linear indexing.\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nidx = [1 3 5];\\nM(idx) \\nans =\\n   2     4     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\u003eGiven a Matrix M, row and column vectors P,Q, output the elements corresponding to the row and column vectors. Try avoiding the use of loops.\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 (tl;dr)\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[M = [2 5 8;\\n     3 6 9; \\n     4 7 10];\\nP = [1 1 2]; Q = [1 3 2];\\nMatrix_VectorIndexes(M,P,Q)\\nans =\\n   2     4     6]]\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":44706,"title":"The Deadly Sin","description":"Melvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates.\r\nCan you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\r\n\r\nExample \r\n  \r\n\r\n  Input:\r\nx = [5 3]\r\n\r\n  \r\nExplanation:\r\nDenoting Melvyn as M, Banner as B\r\n\r\nM=5, B=3 - Banner eats 3 chocolates of Melvyn.\r\n\r\nM=2, B=3 - Melvyn eats 2 chocolates of Banner.\r\n\r\nM=2, B=1 - Banner eats 1 chocolate of Melvyn.\r\n\r\nM=1, B=1 - Since they have the same no of candies, they stop quarreling.\r\n\r\nTotal candies left: 2 \r\n\r\n  Output:\r\n  y = 2\r\n","description_html":"\u003cp\u003eMelvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates.\r\nCan you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:\r\nx = [5 3]\r\n\u003c/pre\u003e\u003cp\u003eExplanation:\r\nDenoting Melvyn as M, Banner as B\u003c/p\u003e\u003cp\u003eM=5, B=3 - Banner eats 3 chocolates of Melvyn.\u003c/p\u003e\u003cp\u003eM=2, B=3 - Melvyn eats 2 chocolates of Banner.\u003c/p\u003e\u003cp\u003eM=2, B=1 - Banner eats 1 chocolate of Melvyn.\u003c/p\u003e\u003cp\u003eM=1, B=1 - Since they have the same no of candies, they stop quarreling.\u003c/p\u003e\u003cp\u003eTotal candies left: 2\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eOutput:\r\ny = 2\r\n\u003c/pre\u003e","function_template":"function y = the_deadly_sin(x)\r\n  % Try to be witty. The problem is not that difficult to figure out.\r\nend","test_suite":"%%\r\nx = [5 3];\r\ny_correct = 2;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [10 10];\r\ny_correct = 20;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [4 8];\r\ny_correct = 8;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [30 12];\r\ny_correct = 12;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [42 91];\r\ny_correct = 14;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n\r\n%%\r\nx = [700 80];\r\ny_correct = 40;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [638 899];\r\ny_correct = 58;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n%%\r\nx = [819 949];\r\ny_correct = 26;\r\nassert(isequal(the_deadly_sin(x),y_correct))\r\n\r\n\r\nx = [500 500];\r\ny_correct = 1000;\r\nassert(isequal(the_deadly_sin(x),y_correct))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":195572,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":27,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2018-08-02T23:07:17.000Z","updated_at":"2018-08-02T23:08:40.000Z","published_at":"2018-08-02T23:07:17.000Z","restored_at":"2018-10-10T14:57:50.000Z","restored_by":null,"spam":false,"simulink":false,"admin_reviewed":true,"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\u003eMelvyn and Banner are fighting over chocolates. Melvyn has X chocolates, while Banner has Y. Whoever has a lesser number of chocolates eats as many chocolates as he has from the other's collection. This eatfest war continues till either they have the same number of chocolates, or at least one of them is left with no chocolates. Can you help Eliza predict the total number of chocolates they'll be left with at the end of their war?\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:\\nx = [5 3]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExplanation: Denoting Melvyn as M, Banner as B\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\u003eM=5, B=3 - Banner eats 3 chocolates of Melvyn.\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\u003eM=2, B=3 - Melvyn eats 2 chocolates of Banner.\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\u003eM=2, B=1 - Banner eats 1 chocolate of Melvyn.\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\u003eM=1, B=1 - Since they have the same no of candies, they stop quarreling.\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\u003eTotal candies left: 2\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:\\ny = 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":54440,"title":"Create an arrow matrix","description":"An arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \r\n                                        \r\n                                        \r\n\r\nWrite a function that takes the number of rows and columns (for N \u003e= 3) as an input, and returns the corresponding arrow matrix.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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=\"block-size: 305px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 152.5px; transform-origin: 407px 152.5px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 164px; 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 82px; text-align: left; transform-origin: 384px 82px; 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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e                                        \u003c/span\u003e\u003c/span\u003e\u003cimg class=\"imageNode\" width=\"199\" height=\"158\" style=\"vertical-align: baseline;width: 199px;height: 158px\" src=\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMy4yMDQgMjUzMy40OSAzMzMuMjA0IDI1MzMuNDkgNjM3LjU1IDIxMzcuMiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjUzMy40OSAzMzMuMjA0IDI5MjkuNzcgMzMzLjIwNCAyOTI5Ljc3IDYzNy41NSAyNTMzLjQ5IDYzNy41NVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDYzNy41NSAxMzQ0LjYzIDYzNy41NSAxMzQ0LjYzIDk1NC43NCA5NDguMzQ5IDk1NC43NFoiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDYzNy41NSAxNzQwLjkyIDYzNy41NSAxNzQwLjkyIDk1NC43NCAxMzQ0LjYzIDk1NC43NFoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDYzNy41NSAyMTM3LjIgNjM3LjU1IDIxMzcuMiA5NTQuNzQgMTc0MC45MiA5NTQuNzRaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDYzNy41NSAyNTMzLjQ5IDYzNy41NSAyNTMzLjQ5IDk1NC43NCAyMTM3LjIgOTU0Ljc0WiIgZmlsbD0iI0Y4Q0JBRCIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgNjM3LjU1IDI5MjkuNzcgNjM3LjU1IDI5MjkuNzcgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgOTU0Ljc0IDEzNDQuNjMgOTU0Ljc0IDEzNDQuNjMgMTI3MS45MyA5NDguMzQ5IDEyNzEuOTNaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyA5NTQuNzQgMTc0MC45MiA5NTQuNzQgMTc0MC45MiAxMjcxLjkzIDEzNDQuNjMgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDk1NC43NCAyMTM3LjIgOTU0Ljc0IDIxMzcuMiAxMjcxLjkzIDE3NDAuOTIgMTI3MS45M1oiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0IDI1MzMuNDkgMTI3MS45MyAyMTM3LjIgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDk1NC43NCAyOTI5Ljc3IDk1NC43NCAyOTI5Ljc3IDEyNzEuOTMgMjUzMy40OSAxMjcxLjkzWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMTI3MS45MyAxMzQ0LjYzIDEyNzEuOTMgMTM0NC42MyAxNTg5LjEyIDk0OC4zNDkgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDEyNzEuOTMgMTc0MC45MiAxMjcxLjkzIDE3NDAuOTIgMTU4OS4xMiAxMzQ0LjYzIDE1ODkuMTJaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAxMjcxLjkzIDIxMzcuMiAxMjcxLjkzIDIxMzcuMiAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgMTI3MS45MyAyNTMzLjQ5IDEyNzEuOTMgMjUzMy40OSAxNTg5LjEyIDIxMzcuMiAxNTg5LjEyWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMTI3MS45MyAyOTI5Ljc3IDEyNzEuOTMgMjkyOS43NyAxNTg5LjEyIDI1MzMuNDkgMTU4OS4xMloiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDE1ODkuMTIgMTM0NC42MyAxNTg5LjEyIDEzNDQuNjMgMTkwNi4zMSA5NDguMzQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMiAxNzQwLjkyIDE5MDYuMzEgMTM0NC42MyAxOTA2LjMxWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTE3NDAuOTIgMTU4OS4xMiAyMTM3LjIgMTU4OS4xMiAyMTM3LjIgMTkwNi4zMSAxNzQwLjkyIDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDE1ODkuMTIgMjUzMy40OSAxNTg5LjEyIDI1MzMuNDkgMTkwNi4zMSAyMTM3LjIgMTkwNi4zMVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDE1ODkuMTIgMjkyOS43NyAxNTg5LjEyIDI5MjkuNzcgMTkwNi4zMSAyNTMzLjQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAzMzAuOTEyIDEzNDQuNjMgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzAuOTEyIDE3NDAuOTIgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMC45MTIgMjEzNy4yIDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMzMwLjkxMiAyNTMzLjQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggNjM3LjU1IDI5MzIuMDYgNjM3LjU1IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCA5NTQuNzQgMjkzMi4wNiA5NTQuNzQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDEyNzEuOTMgMjkzMi4wNiAxMjcxLjkzIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCAxNTg5LjEyIDI5MzIuMDYgMTU4OS4xMiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMzMwLjkxMiA5NDguMzQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI5MjkuNzcgMzMwLjkxMiAyOTI5Ljc3IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggMzMzLjIwNCAyOTMyLjA2IDMzMy4yMDQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDE5MDYuMzEgMjkzMi4wNiAxOTA2LjMxIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48dGV4dCBmb250LWZhbWlseT0iQ2FsaWJyaSxDYWxpYnJpX01TRm9udFNlcnZpY2Usc2Fucy1zZXJpZiIgZm9udC13ZWlnaHQ9IjQwMCIgZm9udC1zaXplPSIxMjgiIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIDEgMTExMy44NCA1MjgpIj4xPHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjAiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMzExIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjM5Ni4yODUiIHk9IjMxMSI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSI3OTIuNTciIHk9IjMxMSI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIzMTEiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTU4NS4xNCIgeT0iMzExIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjAiIHk9IjYyOCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSI2MjgiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iNzkyLjU3IiB5PSI2MjgiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\" data-image-state=\"image-loaded\"\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003eWrite a function that takes the number of rows and columns (for \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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eN\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: 0px 0px; transform-origin: 0px 0px; \"\u003e\u003cspan style=\"\"\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = arrow(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 3;\r\ny_correct = [1 0 1; 0 1 1; 1 1 1];\r\nassert(isequal(arrow(x),y_correct))\r\n\r\n%%\r\nx = 6;\r\ny_correct = [1 0 0 0 0 1; 0 1 0 0 0 1; 0 0 1 0 0 1; 0 0 0 1 0 1; 0 0 0 0 1 1; 1 1 1 1 1 1];\r\nassert(isequal(arrow(x),y_correct))","published":true,"deleted":false,"likes_count":11,"comments_count":1,"created_by":571375,"edited_by":571375,"edited_at":"2022-10-03T14:11:46.000Z","deleted_by":null,"deleted_at":null,"solvers_count":560,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2022-05-03T17:40:18.000Z","updated_at":"2026-03-20T13:55:48.000Z","published_at":"2022-10-03T14:11:46.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\u003eAn arrow matrix is a square matrix that contains ones on the diagonal, the last column, and last row. \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\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\u003e                                        \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:customXml w:element=\\\"image\\\"\u003e\u003cw:customXmlPr\u003e\u003cw:attr w:name=\\\"height\\\" w:val=\\\"158\\\"/\u003e\u003cw:attr w:name=\\\"width\\\" w:val=\\\"199\\\"/\u003e\u003cw:attr w:name=\\\"verticalAlign\\\" w:val=\\\"baseline\\\"/\u003e\u003cw:attr w:name=\\\"altText\\\" w:val=\\\"\\\"/\u003e\u003cw:attr w:name=\\\"relationshipId\\\" w:val=\\\"rId1\\\"/\u003e\u003c/w:customXmlPr\u003e\u003c/w:customXml\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\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\u003eWrite a function that takes the number of rows and columns (for \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eN\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u0026gt;= 3) as an input, and returns the corresponding arrow matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/image\",\"target\":\"/media/image1.svg+xml\",\"relationshipId\":\"rId1\"}]},{\"partUri\":\"/media/image1.svg+xml\",\"contentType\":\"image/svg+xml\",\"content\":\"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTk4OSIgaGVpZ2h0PSIxNTgxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBvdmVyZmxvdz0iaGlkZGVuIj48ZGVmcz48Y2xpcFBhdGggaWQ9ImNsaXAwIj48cmVjdCB4PSI5NDYiIHk9IjMzMCIgd2lkdGg9IjE5ODkiIGhlaWdodD0iMTU4MSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC05NDYgLTMzMCkiPjxwYXRoIGQ9Ik05NDguMzQ5IDMzMy4yMDQgMTM0NC42MyAzMzMuMjA0IDEzNDQuNjMgNjM3LjU1IDk0OC4zNDkgNjM3LjU1WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTEzNDQuNjMgMzMzLjIwNCAxNzQwLjkyIDMzMy4yMDQgMTc0MC45MiA2MzcuNTUgMTM0NC42MyA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzMuMjA0IDIxMzcuMiAzMzMuMjA0IDIxMzcuMiA2MzcuNTUgMTc0MC45MiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMy4yMDQgMjUzMy40OSAzMzMuMjA0IDI1MzMuNDkgNjM3LjU1IDIxMzcuMiA2MzcuNTVaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjUzMy40OSAzMzMuMjA0IDI5MjkuNzcgMzMzLjIwNCAyOTI5Ljc3IDYzNy41NSAyNTMzLjQ5IDYzNy41NVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDYzNy41NSAxMzQ0LjYzIDYzNy41NSAxMzQ0LjYzIDk1NC43NCA5NDguMzQ5IDk1NC43NFoiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDYzNy41NSAxNzQwLjkyIDYzNy41NSAxNzQwLjkyIDk1NC43NCAxMzQ0LjYzIDk1NC43NFoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDYzNy41NSAyMTM3LjIgNjM3LjU1IDIxMzcuMiA5NTQuNzQgMTc0MC45MiA5NTQuNzRaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDYzNy41NSAyNTMzLjQ5IDYzNy41NSAyNTMzLjQ5IDk1NC43NCAyMTM3LjIgOTU0Ljc0WiIgZmlsbD0iI0Y4Q0JBRCIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgNjM3LjU1IDI5MjkuNzcgNjM3LjU1IDI5MjkuNzcgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0WiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgOTU0Ljc0IDEzNDQuNjMgOTU0Ljc0IDEzNDQuNjMgMTI3MS45MyA5NDguMzQ5IDEyNzEuOTNaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyA5NTQuNzQgMTc0MC45MiA5NTQuNzQgMTc0MC45MiAxMjcxLjkzIDEzNDQuNjMgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xNzQwLjkyIDk1NC43NCAyMTM3LjIgOTU0Ljc0IDIxMzcuMiAxMjcxLjkzIDE3NDAuOTIgMTI3MS45M1oiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgOTU0Ljc0IDI1MzMuNDkgOTU0Ljc0IDI1MzMuNDkgMTI3MS45MyAyMTM3LjIgMTI3MS45M1oiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDk1NC43NCAyOTI5Ljc3IDk1NC43NCAyOTI5Ljc3IDEyNzEuOTMgMjUzMy40OSAxMjcxLjkzWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMTI3MS45MyAxMzQ0LjYzIDEyNzEuOTMgMTM0NC42MyAxNTg5LjEyIDk0OC4zNDkgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0xMzQ0LjYzIDEyNzEuOTMgMTc0MC45MiAxMjcxLjkzIDE3NDAuOTIgMTU4OS4xMiAxMzQ0LjYzIDE1ODkuMTJaIiBmaWxsPSIjRjhDQkFEIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAxMjcxLjkzIDIxMzcuMiAxMjcxLjkzIDIxMzcuMiAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMloiIGZpbGw9IiNGOENCQUQiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yMTM3LjIgMTI3MS45MyAyNTMzLjQ5IDEyNzEuOTMgMjUzMy40OSAxNTg5LjEyIDIxMzcuMiAxNTg5LjEyWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMTI3MS45MyAyOTI5Ljc3IDEyNzEuOTMgMjkyOS43NyAxNTg5LjEyIDI1MzMuNDkgMTU4OS4xMloiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDguMzQ5IDE1ODkuMTIgMTM0NC42MyAxNTg5LjEyIDEzNDQuNjMgMTkwNi4zMSA5NDguMzQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAxNTg5LjEyIDE3NDAuOTIgMTU4OS4xMiAxNzQwLjkyIDE5MDYuMzEgMTM0NC42MyAxOTA2LjMxWiIgZmlsbD0iI0JERDdFRSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTE3NDAuOTIgMTU4OS4xMiAyMTM3LjIgMTU4OS4xMiAyMTM3LjIgMTkwNi4zMSAxNzQwLjkyIDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDE1ODkuMTIgMjUzMy40OSAxNTg5LjEyIDI1MzMuNDkgMTkwNi4zMSAyMTM3LjIgMTkwNi4zMVoiIGZpbGw9IiNCREQ3RUUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik0yNTMzLjQ5IDE1ODkuMTIgMjkyOS43NyAxNTg5LjEyIDI5MjkuNzcgMTkwNi4zMSAyNTMzLjQ5IDE5MDYuMzFaIiBmaWxsPSIjQkREN0VFIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTM0NC42MyAzMzAuOTEyIDEzNDQuNjMgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMTc0MC45MiAzMzAuOTEyIDE3NDAuOTIgMTkwOC42IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNMjEzNy4yIDMzMC45MTIgMjEzNy4yIDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI1MzMuNDkgMzMwLjkxMiAyNTMzLjQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggNjM3LjU1IDI5MzIuMDYgNjM3LjU1IiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCA5NTQuNzQgMjkzMi4wNiA5NTQuNzQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDEyNzEuOTMgMjkzMi4wNiAxMjcxLjkzIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48cGF0aCBkPSJNOTQ2LjA1OCAxNTg5LjEyIDI5MzIuMDYgMTU4OS4xMiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0OC4zNDkgMzMwLjkxMiA5NDguMzQ5IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTI5MjkuNzcgMzMwLjkxMiAyOTI5Ljc3IDE5MDguNiIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2Utd2lkdGg9IjQuNTgzMzMiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS1taXRlcmxpbWl0PSIxMCIgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIi8+PHBhdGggZD0iTTk0Ni4wNTggMzMzLjIwNCAyOTMyLjA2IDMzMy4yMDQiIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLXdpZHRoPSI0LjU4MzMzIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjxwYXRoIGQ9Ik05NDYuMDU4IDE5MDYuMzEgMjkzMi4wNiAxOTA2LjMxIiBzdHJva2U9IiMwMDAwMDAiIHN0cm9rZS13aWR0aD0iNC41ODMzMyIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLW1pdGVybGltaXQ9IjEwIiBmaWxsPSJub25lIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiLz48dGV4dCBmb250LWZhbWlseT0iQ2FsaWJyaSxDYWxpYnJpX01TRm9udFNlcnZpY2Usc2Fucy1zZXJpZiIgZm9udC13ZWlnaHQ9IjQwMCIgZm9udC1zaXplPSIxMjgiIHRyYW5zZm9ybT0ibWF0cml4KDEgMCAwIDEgMTExMy44NCA1MjgpIj4xPHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIwIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjAiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMzExIj4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjM5Ni4yODUiIHk9IjMxMSI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSI3OTIuNTciIHk9IjMxMSI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIzMTEiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTU4NS4xNCIgeT0iMzExIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjAiIHk9IjYyOCI+MDwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSI2MjgiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iNzkyLjU3IiB5PSI2MjgiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMTE4OC44NSIgeT0iNjI4Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjYyOCI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIwIiB5PSI5NDYiPjA8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMzk2LjI4NSIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iOTQ2Ij4wPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjExODguODUiIHk9Ijk0NiI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxNTg1LjE0IiB5PSI5NDYiPjE8L3RzcGFuPjx0c3BhbiBmb250LXNpemU9IjEyOCIgeD0iMCIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIzOTYuMjg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9Ijc5Mi41NyIgeT0iMTI2MyI+MTwvdHNwYW4+PHRzcGFuIGZvbnQtc2l6ZT0iMTI4IiB4PSIxMTg4Ljg1IiB5PSIxMjYzIj4xPC90c3Bhbj48dHNwYW4gZm9udC1zaXplPSIxMjgiIHg9IjE1ODUuMTQiIHk9IjEyNjMiPjE8L3RzcGFuPjwvdGV4dD48L2c+PC9zdmc+\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":61020,"title":"The Case of the Missing Prototype - Count the Fingerprints Found at the Lab Door to Begin Your Investigation","description":"You arrive at the Innovation Lab where the secret prototype was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector prints.\r\nHere, 1 represents a fingerprint found and 0 means a clean spot.\r\nYour first task as Detective Alex Verma is to count the total number of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\r\nReturn a single number — the count of 1s in prints.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 76.5px; transform-origin: 408px 76.5px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou arrive at the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003eInnovation Lab\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e where the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"text-decoration: underline; text-decoration-line: underline; \"\u003esecret prototype\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eprints\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eHere, \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e1\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e represents a\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003e fingerprint found\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e and \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e0\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e means a \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eclean spot\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour first task as Detective Alex Verma is to \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ecount the total number\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a single number — the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003ecount of \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; font-weight: 700; \"\u003e1\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003es\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eprints\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function count = countFingerprints(prints)\r\n  y = x;\r\nend","test_suite":"%%\r\nprints = [1 0 1 1 0 0 1];\r\nprints_correct = 4;\r\nassert(isequal(countFingerprints(prints),prints_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":0,"created_by":4953963,"edited_by":4953963,"edited_at":"2025-10-20T15:41:28.000Z","deleted_by":null,"deleted_at":null,"solvers_count":65,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T15:39:33.000Z","updated_at":"2026-04-03T03:44:06.000Z","published_at":"2025-10-20T15:41:28.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\u003eYou arrive at the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eInnovation Lab\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e where the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:u/\u003e\u003c/w:rPr\u003e\u003cw:t\u003esecret prototype\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e was stolen. The door has been dusted for fingerprints, and a technician provides you with a binary vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprints\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eHere, \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e represents a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e fingerprint found\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e and \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e0\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e means a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eclean spot\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYour first task as Detective Alex Verma is to \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecount the total number\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of fingerprints discovered at the scene. Every fingerprint brings you one step closer to the truth.\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\u003eReturn a single number — the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ecount of \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e1\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003es\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eprints\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\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":1991,"title":"Find the index of nth maximum of a row vector of real numbers","description":"Given a vector of real numbers x, find the index idx of _n_ th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\r\n\r\n*Example 1:*\r\n\r\nInput: x = [2 4.5 3 1 3.33], n = 4\r\n\r\nOutput: idx = 1, since 4th maximum is 2\r\n\r\n*Example 2:*\r\nInput: x = [2 4.5 3.33 3 1 3.33], n = 2\r\n\r\nOutput: idx = [3 6], since 2nd maximum is 3.33\r\n","description_html":"\u003cp\u003eGiven a vector of real numbers x, find the index idx of \u003ci\u003en\u003c/i\u003e th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample 1:\u003c/b\u003e\u003c/p\u003e\u003cp\u003eInput: x = [2 4.5 3 1 3.33], n = 4\u003c/p\u003e\u003cp\u003eOutput: idx = 1, since 4th maximum is 2\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample 2:\u003c/b\u003e\r\nInput: x = [2 4.5 3.33 3 1 3.33], n = 2\u003c/p\u003e\u003cp\u003eOutput: idx = [3 6], since 2nd maximum is 3.33\u003c/p\u003e","function_template":"function idx = findMaxIndex(x,n)\r\n% Enter your code here\r\nend","test_suite":"%%\r\nx = [2 4.5 3 1 3.33]; n = 4;\r\ny_correct = 1;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33]; n = 5;\r\ny_correct = 4;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01]; n = 1;\r\ny_correct = 7;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01]; n = 8;\r\ny_correct = 6;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3 1 3.33 eps inf 0.01 realmax realmin]; n = 2;\r\ny_correct = 9;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [-2.23 1 0 -6.65 2.63 -realmax inf 0]; n = 8\r\ny_correct = 6;\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 3.33 3 1 3.33]; n = 2;\r\ny_correct = [3 6];\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n%%\r\nx = [2 4.5 pi eps eps pi 0 pi 6]; n = 3;\r\ny_correct = [3 6 8];\r\nassert(isequal(findMaxIndex(x,n),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":1,"created_by":18241,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":76,"test_suite_updated_at":"2013-11-16T05:39:46.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2013-11-15T15:19:06.000Z","updated_at":"2026-03-23T11:12:29.000Z","published_at":"2013-11-15T15:19: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\u003eGiven a vector of real numbers x, find the index idx of\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003en\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e th maximum value. If nth maximum occurs more than once, return the indices of all those occurences.\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 1:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput: x = [2 4.5 3 1 3.33], n = 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\u003eOutput: idx = 1, since 4th maximum is 2\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:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample 2:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e Input: x = [2 4.5 3.33 3 1 3.33], n = 2\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\u003eOutput: idx = [3 6], since 2nd maximum is 3.33\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":1911,"title":"Find the index of the first occurrence of a value in a matrix","description":"Given a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. For example\r\n \r\n input =\r\n\r\n     0     0     0     0\r\n    -1    -1     0     1\r\n    -1     1     0    -1\r\n     0     0     0     1\r\n\r\nFind row number of first instance of -1 in each column\r\n\r\n output = [2 2 NaN 3]\r\n\r\n\r\n","description_html":"\u003cp\u003eGiven a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. For example\u003c/p\u003e\u003cpre\u003e input =\u003c/pre\u003e\u003cpre\u003e     0     0     0     0\r\n    -1    -1     0     1\r\n    -1     1     0    -1\r\n     0     0     0     1\u003c/pre\u003e\u003cp\u003eFind row number of first instance of -1 in each column\u003c/p\u003e\u003cpre\u003e output = [2 2 NaN 3]\u003c/pre\u003e","function_template":"function y = findfirst(x)\r\n  y = (x==-1);\r\nend","test_suite":"%%\r\nx = [0 1;-1 0];\r\ny_correct = [2 NaN];\r\nassert(isequaln(findfirst(x),y_correct))\r\n\r\n%%\r\nx = [0 0 -1;2 -1 0];\r\ny_correct = [NaN 2 1];\r\nassert(isequaln(findfirst(x),y_correct))\r\n\r\n%%\r\nx = [0 1 0 -1;-1 -1 0 1;-1 1 0 -1;0 0 0 1];\r\ny_correct = [2 2 NaN 1];\r\nassert(isequaln(findfirst(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":11070,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":63,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2013-10-03T02:46:18.000Z","updated_at":"2025-02-06T02:49:16.000Z","published_at":"2013-10-03T02:46:18.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a matrix of scalars, find the first occurrence of -1 in each column. Output NaN for a column which does not contain the value. 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[ input =\\n\\n     0     0     0     0\\n    -1    -1     0     1\\n    -1     1     0    -1\\n     0     0     0     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\u003eFind row number of first instance of -1 in each column\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 NaN 3]]]\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":61034,"title":"The MATLAB Treasure Hunt – Identify the Hidden Pattern Within the Maze of Numbers","description":"The compass leads you to an underground chamber covered in numbers carved into the walls — a maze of digits that glows in mysterious patterns.\r\nThe inscription reads: “Only the even paths shall open.”\r\nGiven a vector a of numbers, extract and return a new vector b containing only the even numbers, preserving their original order.\r\nThese even numbers form the correct path through the Maze of Numbers.","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 153px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 76.5px; transform-origin: 408px 76.5px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe compass leads you to an underground chamber covered in numbers carved into the walls — a \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003emaze of digits\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e that glows in mysterious patterns.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe inscription reads: \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-style: italic; \"\u003e“Only the even paths shall open.”\u003c/span\u003e\u003c/span\u003e\u003c/div\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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003ea\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of numbers, extract and return a new vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003eb\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e containing \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eonly the even numbers\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, preserving their original order.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThese even numbers form the correct path through the Maze of Numbers.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y =mazePath(a)\r\n  y = x;\r\nend","test_suite":"%%\r\na = [3 8 11 24 19 42];\r\ny_correct = [8 24 42];\r\nassert(isequal(mazePath(a),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":75,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-21T09:32:24.000Z","updated_at":"2026-03-10T12:47:56.000Z","published_at":"2025-10-21T09:32:24.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\u003eThe compass leads you to an underground chamber covered in numbers carved into the walls — a \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003emaze of digits\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e that glows in mysterious patterns.\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 inscription reads: \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003e“Only the even paths shall open.”\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\u003eGiven a vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003ea\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of numbers, extract and return a new vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eb\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e containing \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eonly the even numbers\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, preserving their original order.\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\u003eThese even numbers form the correct path through the Maze of Numbers.\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":61026,"title":"The Case of the Missing Prototype – Detect Tampered Sensor Readings from the Stolen Device’s Data Logs","description":"You’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector data, but something seems off — certain values are negative, indicating possible tampering.\r\nYour task as Detective Alex Verma is to identify all readings that were tampered with.\r\nReturn a row vector containing the indices of all negative values in data.\r\nIf no tampering is found, return an empty vector.\r\nEvery negative entry is another clue toward catching the thief!","description_html":"\u003cdiv style = \"text-align: start; line-height: 20.44px; 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; white-space: normal; \"\u003e\u003cdiv style=\"block-size: 162px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 408px 81px; transform-origin: 408px 81px; 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: 385px 21px; text-align: left; transform-origin: 385px 21px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYou’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003edata\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, but something seems off — certain values are \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003enegative\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e, indicating possible tampering.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eYour task as Detective Alex Verma is to identify all readings that were tampered with.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eReturn a row vector containing the \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-weight: 700; \"\u003eindices\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e of all negative values in \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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"font-family: Menlo, Monaco, Consolas, \u0026quot;Courier New\u0026quot;, monospace; \"\u003edata\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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf no tampering is found, return an empty vector.\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: 385px 10.5px; text-align: left; transform-origin: 385px 10.5px; white-space-collapse: preserve; 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: 0px 0px; transform-origin: 0px 0px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eEvery negative entry is another clue toward catching the thief!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = detectTampering(data)\r\n  y = x;\r\nend","test_suite":"%%\r\ndata = [2 -5 3 -1 6];\r\ny_correct = [2 4];\r\nassert(isequal(detectTampering(data),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":4953963,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":51,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2025-10-20T16:55:42.000Z","updated_at":"2026-04-03T03:56:39.000Z","published_at":"2025-10-20T16:55:42.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\u003eYou’ve recovered partial sensor data from the stolen prototype.Each reading is stored in a numeric vector \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edata\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, but something seems off — certain values are \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003enegative\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e, indicating possible tampering.\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\u003eYour task as Detective Alex Verma is to identify all readings that were tampered with.\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\u003eReturn a row vector containing the \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eindices\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e of all negative values in \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:rFonts w:cs=\\\"monospace\\\"/\u003e\u003c/w:rPr\u003e\u003cw:t\u003edata\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf no tampering is found, return an empty vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eEvery negative entry is another clue toward catching the thief!\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\"}]}"}],"term":"tag:\"indexing\"","current_player_id":null,"fields":[{"name":"page","type":"integer","callback":null,"default":1,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"per_page","type":"integer","callback":null,"default":50,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"sort","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":null,"prepend":true},{"name":"body","type":"text","callback":null,"default":"*:*","directive":null,"facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":false},{"name":"group","type":"string","callback":null,"default":null,"directive":"group","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"difficulty_rating_bin","type":"string","callback":null,"default":null,"directive":"difficulty_rating_bin","facet":true,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"id","type":"integer","callback":null,"default":null,"directive":"id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"tag","type":"string","callback":null,"default":null,"directive":"tag","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"product","type":"string","callback":null,"default":null,"directive":"product","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_at","type":"timeframe","callback":{},"default":null,"directive":"created_at","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"profile_id","type":"integer","callback":null,"default":null,"directive":"author_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"created_by","type":"string","callback":null,"default":null,"directive":"author","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player_id","type":"integer","callback":null,"default":null,"directive":"solver_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"player","type":"string","callback":null,"default":null,"directive":"solver","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"solvers_count","type":"integer","callback":null,"default":null,"directive":"solvers_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"comments_count","type":"integer","callback":null,"default":null,"directive":"comments_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"likes_count","type":"integer","callback":null,"default":null,"directive":"likes_count","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leader_id","type":"integer","callback":null,"default":null,"directive":"leader_id","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true},{"name":"leading_solution","type":"integer","callback":null,"default":null,"directive":"leading_solution","facet":null,"facet_method":"and","operator":null,"param":"term","static":null,"prepend":true}],"filters":[{"name":"asset_type","type":"string","callback":null,"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":null,"static":"\"cody:problem\"","prepend":true},{"name":"profile_id","type":"integer","callback":{},"default":null,"directive":null,"facet":null,"facet_method":"and","operator":null,"param":"author_id","static":null,"prepend":true}],"query":{"params":{"per_page":50,"term":"tag:\"indexing\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"indexing\"","","\"","indexing","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2b690\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac4ae2b5f0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4ae29390\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2e570\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac4ae2beb0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac4ae2bc30\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac4ae2b870\u003e":"tag:\"indexing\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2b870\u003e":"tag:\"indexing\""},"queried_facets":{}},"query_backend":{"connection":{"configuration":{"index_url":"http://index-op-v2/solr/","query_url":"http://search-op-v2/solr/","direct_access_index_urls":["http://index-op-v2/solr/"],"direct_access_query_urls":["http://search-op-v2/solr/"],"timeout":10,"vhost":"search","exchange":"search.topic","heartbeat":30,"pre_index_mode":false,"host":"rabbitmq-eks","port":5672,"username":"search","password":"J3bGPZzQ7asjJcCk","virtual_host":"search","indexer":"amqp","http_logging":"true","core":"cody"},"query_connection":{"uri":"http://search-op-v2/solr/cody/","proxy":null,"connection":{"parallel_manager":null,"headers":{"User-Agent":"Faraday v1.0.1"},"params":{},"options":{"params_encoder":"Faraday::FlatParamsEncoder","proxy":null,"bind":null,"timeout":null,"open_timeout":null,"read_timeout":null,"write_timeout":null,"boundary":null,"oauth":null,"context":null,"on_data":null},"ssl":{"verify":true,"ca_file":null,"ca_path":null,"verify_mode":null,"cert_store":null,"client_cert":null,"client_key":null,"certificate":null,"private_key":null,"verify_depth":null,"version":null,"min_version":null,"max_version":null},"default_parallel_manager":null,"builder":{"adapter":{"name":"Faraday::Adapter::NetHttp","args":[],"block":null},"handlers":[{"name":"Faraday::Response::RaiseError","args":[],"block":null}],"app":{"app":{"ssl_cert_store":{"verify_callback":null,"error":null,"error_string":null,"chain":null,"time":null},"app":{},"connection_options":{},"config_block":null}}},"url_prefix":"http://search-op-v2/solr/cody/","manual_proxy":false,"proxy":null},"update_format":"RSolr::JSON::Generator","update_path":"update","options":{"url":"http://search-op-v2/solr/cody"}}},"query":{"params":{"per_page":50,"term":"tag:\"indexing\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"indexing\"","","\"","indexing","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2b690\u003e":null,"#\u003cMathWorks::Search::Field:0x00007fac4ae2b5f0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fac4ae29390\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2e570\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fac4ae2beb0\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fac4ae2bc30\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fac4ae2b870\u003e":"tag:\"indexing\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fac4ae2b870\u003e":"tag:\"indexing\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":42675,"difficulty_rating":"easy"},{"id":59546,"difficulty_rating":"easy"},{"id":42678,"difficulty_rating":"easy"},{"id":2121,"difficulty_rating":"easy"},{"id":44326,"difficulty_rating":"easy"},{"id":43655,"difficulty_rating":"easy"},{"id":47118,"difficulty_rating":"easy"},{"id":44242,"difficulty_rating":"easy"},{"id":57570,"difficulty_rating":"easy"},{"id":57585,"difficulty_rating":"easy"},{"id":2092,"difficulty_rating":"easy"},{"id":45472,"difficulty_rating":"easy"},{"id":58563,"difficulty_rating":"easy"},{"id":3107,"difficulty_rating":"easy"},{"id":42648,"difficulty_rating":"easy"},{"id":43607,"difficulty_rating":"easy"},{"id":43144,"difficulty_rating":"easy"},{"id":42679,"difficulty_rating":"easy"},{"id":42982,"difficulty_rating":"easy"},{"id":1741,"difficulty_rating":"easy"},{"id":43682,"difficulty_rating":"easy"},{"id":56155,"difficulty_rating":"easy"},{"id":60704,"difficulty_rating":"easy"},{"id":1671,"difficulty_rating":"easy"},{"id":45485,"difficulty_rating":"easy"},{"id":960,"difficulty_rating":"easy"},{"id":1835,"difficulty_rating":"easy"},{"id":61021,"difficulty_rating":"easy"},{"id":647,"difficulty_rating":"easy"},{"id":646,"difficulty_rating":"easy"},{"id":105,"difficulty_rating":"easy"},{"id":54705,"difficulty_rating":"easy"},{"id":1951,"difficulty_rating":"easy"},{"id":47508,"difficulty_rating":"easy"},{"id":1368,"difficulty_rating":"easy"},{"id":61032,"difficulty_rating":"easy"},{"id":53950,"difficulty_rating":"easy"},{"id":640,"difficulty_rating":"easy-medium"},{"id":1786,"difficulty_rating":"easy-medium"},{"id":2012,"difficulty_rating":"easy-medium"},{"id":56453,"difficulty_rating":"easy-medium"},{"id":44797,"difficulty_rating":"easy-medium"},{"id":44496,"difficulty_rating":"easy-medium"},{"id":44706,"difficulty_rating":"easy-medium"},{"id":54440,"difficulty_rating":"easy-medium"},{"id":61020,"difficulty_rating":"easy-medium"},{"id":1991,"difficulty_rating":"easy-medium"},{"id":1911,"difficulty_rating":"easy-medium"},{"id":61034,"difficulty_rating":"easy-medium"},{"id":61026,"difficulty_rating":"easy-medium"}]}}