{"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":44103,"title":"Find the maxmum value of N*N Matrix","description":"Input\r\n\r\nx=[1 2 3;\r\n4 5 6;\r\n 7 8 9]\r\n\r\noutput:\r\n\r\ny=9","description_html":"\u003cp\u003eInput\u003c/p\u003e\u003cp\u003ex=[1 2 3;\r\n4 5 6;\r\n 7 8 9]\u003c/p\u003e\u003cp\u003eoutput:\u003c/p\u003e\u003cp\u003ey=9\u003c/p\u003e","function_template":"function ans= your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =[1 2 3;\r\n4 9 6;\r\n 7 8 2];\r\ny_correct = 9;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =1;\r\ny_correct =1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =[1 2 3];\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =[8 3;\r\n4 5;\r\n 7 1];\r\ny_correct = 8;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":37163,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2017-05-08T12:40:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-04-25T09:29:42.000Z","updated_at":"2026-02-05T05:10:53.000Z","published_at":"2017-04-25T09:29:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput\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\u003eoutput:\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=9\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":44325,"title":"Matrix Max Finder","description":"Output the maximum value in a matrix","description_html":"\u003cp\u003eOutput the maximum value in a matrix\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = ...;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [3 7; 4 1];\r\ny_correct = 7;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:14:14.000Z","updated_at":"2026-02-23T15:27:32.000Z","published_at":"2017-09-14T17:14:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eOutput the maximum value in a 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":42863,"title":"Replace values out of an interval with the lower or upper values","description":"For a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\r\n\r\nExample\r\n\r\n x= [1 2 3 4 5 1 2 4 6]\r\n\r\n n=[3,5]\r\n\r\n y_correct= [3 3 3 4 5 3 3 4 5]","description_html":"\u003cp\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x= [1 2 3 4 5 1 2 4 6]\u003c/pre\u003e\u003cpre\u003e n=[3,5]\u003c/pre\u003e\u003cpre\u003e y_correct= [3 3 3 4 5 3 3 4 5]\u003c/pre\u003e","function_template":"function y = limit2interval(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(1,25);\r\nn=[0,2];\r\ny_correct = x;\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= [1 2 3 4 5 1 2 4 6];\r\nn=[3,5];\r\ny_correct= [3 3 3 4 5 3 3 4 5];\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= magic(7);\r\nn=[7,14];\r\ny_correct=ones(7)*14-sparse([4 5 3 2 3 1 2 1 7 6 7 5 6],[1 1 2 3 3 4 4 5 5 6 6 7 7],[7 1 7 7 6 7 5 4 7 7 3 7 2])\r\nassert(isequal(limit2interval(x,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":55194,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-28T10:47:32.000Z","updated_at":"2026-02-04T15:47:26.000Z","published_at":"2016-05-28T21:13:31.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 vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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= [1 2 3 4 5 1 2 4 6]\\n\\n n=[3,5]\\n\\n y_correct= [3 3 3 4 5 3 3 4 5]]]\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":1923,"title":"Find the maximum two numbers of every column of a matrix","description":"Find the maximum two numbers of every column of a matrix.\r\n\r\nExample:\r\n\r\nIf we input a matrix \r\n\r\n A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\r\n\r\nwe should get\r\n\r\n B = [ 6 2 5\r\n       4 1 4 ]\r\n","description_html":"\u003cp\u003eFind the maximum two numbers of every column of a matrix.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eIf we input a matrix\u003c/p\u003e\u003cpre\u003e A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\u003c/pre\u003e\u003cp\u003ewe should get\u003c/p\u003e\u003cpre\u003e B = [ 6 2 5\r\n       4 1 4 ]\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4;\r\n     6 0 3;\r\n     4 1 5];\r\ny_correct = [6 2 5;\r\n             4 1 4];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = ones(3);\r\ny_correct = ones(2,3);\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = [ones(1,4); zeros(1,4)];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1:5;\r\n     6:10;\r\n     11:15;\r\n     16:20;\r\n     21:25];\r\ny_correct = [21:25; 16:20];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 5 7 3 47 2  3;\r\n     6 7 1 5 23 1 47;\r\n     7 1 3 2 68 4 11];\r\ny_correct = [7 7 7 5 68 4 47;\r\n             6 5 3 3 47 2 11];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":231,"test_suite_updated_at":"2017-03-15T16:43:08.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-10-08T14:30:23.000Z","updated_at":"2026-03-31T17:07:39.000Z","published_at":"2013-10-08T14:30:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the maximum two numbers of every column of a matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we input a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ A = [ 1 2 4\\n       6 0 3\\n       4 1 5 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewe should get\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ B = [ 6 2 5\\n       4 1 4 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45156,"title":" Find the max element of the array","description":" Find the max element of the array","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: 20.4333px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.2167px; transform-origin: 407px 10.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 136px 8.5px; tab-size: 4; transform-origin: 136px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e Find \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 112px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 112px 8.5px; \"\u003ethe max element of the array\u003c/span\u003e\u003c/span\u003e\u003c/div\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 = [1 2 3 4];\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 7 5 6];\r\ny_correct = 7;\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":6,"comments_count":3,"created_by":343758,"edited_by":223089,"edited_at":"2022-10-13T04:00:14.000Z","deleted_by":null,"deleted_at":null,"solvers_count":2222,"test_suite_updated_at":"2022-10-13T04:00:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-07T17:32:55.000Z","updated_at":"2026-04-03T16:12:01.000Z","published_at":"2019-10-07T17:32:55.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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Find the max element of the array]]\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":58887,"title":"Neural Net: Best Index of Prediction array","description":"The final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\r\nFor the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction matrix.\r\nGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\r\n[case_peak,case_idx]=Prediction(P)\r\nif P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[3;2]\r\n","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: 234px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 117px; transform-origin: 407px 117px; 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: 379px 8px; transform-origin: 379px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\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: 379.5px 8px; transform-origin: 379.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction matrix.\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: 378.5px 8px; transform-origin: 378.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\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: 113px 8px; transform-origin: 113px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e[case_peak,case_idx]=Prediction(P)\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: 373px 8px; transform-origin: 373px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eif P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[3;2]\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 8px; transform-origin: 0px 8px; 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 [case_peak,case_idx]=Prediction(P)\r\n%P provides probability that an input is probably type n\r\n%P may represent [Prob_dog Prob_cat Prob_cow Prob_sheep] when trained on four anaimals\r\n%P may be a [1,n] prediction vector for a single case or\r\n%P may be an [m,n] prediction matrix of m cases\r\n case_peak=max(P);\r\n case_idx=find(P==max(P));\r\nend","test_suite":"%%\r\nvalid=1;\r\n%Binary functions AND/OR/XOR\r\n%input [0 0;0 1;1 0;1 1] cases\r\nPor=[.75 .25;.1 .9;.2 .8;.05 .95]; % [Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Por);\r\nif ~isequal(case_peak,max(Por,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Por,1)\r\n    if case_idx(i)~=find(Por(i,:)==max(Por(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\n%input [0 0;0 1;1 0;1 1] cases\r\nPand=[1 0;.8 0;.9 .1;.1 .9]; %[Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Pand);\r\nif ~isequal(case_peak,max(Pand,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Pand,1)\r\n    if case_idx(i)~=find(Pand(i,:)==max(Pand(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\nPxor=[.9 .2;.1 .8;.3 .8;.8 .1]; % [Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Pxor);\r\nif ~isequal(case_peak,max(Pxor,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Pxor,1)\r\n    if case_idx(i)~=find(Pxor(i,:)==max(Pxor(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\n\r\n\r\nassert(valid)\r\n%%\r\nvalid=1;\r\n%input [dog;cat;cow;sheep] cases\r\n%[Prob-dog Prob-cat Prob-cow Prob-sheep] Notional values\r\nP=[.8 .3 .2 .1;.3 .9 .2 .1;.1 .1 .7 .2;.25 .3 .1 .6]; \r\n[case_peak,case_idx]=Prediction(P);\r\nif ~isequal(case_peak,max(P,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(P,1)\r\n    if case_idx(i)~=find(P(i,:)==max(P(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\nassert(valid)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":3097,"edited_at":"2023-08-19T23:47:40.000Z","deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-08-19T22:24:20.000Z","updated_at":"2026-03-11T13:40:50.000Z","published_at":"2023-08-19T23:47:40.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 final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\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 the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction 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\u003eGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\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[case_peak,case_idx]=Prediction(P)\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 P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[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\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":1041,"title":"Find Index of maximum Value and maximum Value of a vector ","description":"Find the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\r\n\r\nExample:\r\n[1 2 5 7 5 7 4 3] Returns 7 and 4\r\n\r\n[1 4;2 3] Returns 4 and 2","description_html":"\u003cp\u003eFind the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\u003c/p\u003e\u003cp\u003eExample:\r\n[1 2 5 7 5 7 4 3] Returns 7 and 4\u003c/p\u003e\u003cp\u003e[1 4;2 3] Returns 4 and 2\u003c/p\u003e","function_template":"function [max_val, max_idx] = max_val_idx(x)\r\n  max_val=1;\r\n  max_idx=1;\r\nend","test_suite":"%%\r\nseq=randi(5,1,10);\r\nseq_max = max(seq);\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=rand(10);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=randn(10);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=randi(2^15,128,1);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":168,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-20T04:15:52.000Z","updated_at":"2026-03-10T15:33:24.000Z","published_at":"2012-11-20T04:27: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\",\"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\u003eFind the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: [1 2 5 7 5 7 4 3] Returns 7 and 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\u003e[1 4;2 3] Returns 4 and 2\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":42630,"title":"Make visible max values","description":"Make visible maximum values of rows\r\n\r\n input = [1 2 3 4 5;\r\n          6 9 8 2 1;\r\n          2 1 4 5 8;\r\n          1 9 7 9 2];\r\n\r\n output = [0 0 0 0 5;\r\n           0 9 0 0 0;\r\n           0 0 0 0 8;\r\n           0 9 0 9 0];\r\n\r\nI prefer solutions without for/while loops","description_html":"\u003cp\u003eMake visible maximum values of rows\u003c/p\u003e\u003cpre\u003e input = [1 2 3 4 5;\r\n          6 9 8 2 1;\r\n          2 1 4 5 8;\r\n          1 9 7 9 2];\u003c/pre\u003e\u003cpre\u003e output = [0 0 0 0 5;\r\n           0 9 0 0 0;\r\n           0 0 0 0 8;\r\n           0 9 0 9 0];\u003c/pre\u003e\u003cp\u003eI prefer solutions without for/while loops\u003c/p\u003e","function_template":"function y = visibleMax(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5;6 9 8 2 1;2 1 4 5 8;1 9 7 9 2];\r\ny_correct = [0 0 0 0 5;0 9 0 0 0;0 0 0 0 8;0 9 0 9 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n%%\r\nx = [10 20 40 85 96 15 14 12;14 15 12 16 19 17 15 0];\r\ny_correct = [0 0 0 0 96 0 0 0;0 0 0 0 19 0 0 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n\r\n%%\r\nx = [2 4 9; 9 1 0; 8 4 1; 7 5 6; 4 2 1; 4 5 6; 1 9 5];\r\ny_correct = [0 0 9;9 0 0;8 0 0;7 0 0;4 0 0;0 0 6;0 9 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n\r\n%%\r\nx = [5; 8 ; 9 ; 1 ; 3 ; 4]; \r\ny_correct = [5; 8 ; 9 ; 1 ; 3 ; 4];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n%%\r\nx =  [2 4; Inf 1; 9 2; NaN 5];\r\ny_correct =  [0 4;Inf 0;9 0;0 5];\r\nassert(isequal(visibleMax(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":46,"test_suite_updated_at":"2015-09-21T17:07:34.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-09-21T17:05:09.000Z","updated_at":"2025-12-07T21:01:10.000Z","published_at":"2015-09-21T17:05:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMake visible maximum values of rows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ input = [1 2 3 4 5;\\n          6 9 8 2 1;\\n          2 1 4 5 8;\\n          1 9 7 9 2];\\n\\n output = [0 0 0 0 5;\\n           0 9 0 0 0;\\n           0 0 0 0 8;\\n           0 9 0 9 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\u003eI prefer solutions without for/while loops\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":2345,"title":"row-th maximum row elements","description":"Input a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\r\n\r\nExample: \r\n\r\nInput:\r\n\r\n    a=[  1 2 4; \r\n         4 5 5; \r\n         8 9 1];\r\n\r\nOutput:\r\n\r\n  v=[4 5 1]\r\n\r\n","description_html":"\u003cp\u003eInput a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput:\u003c/p\u003e\u003cpre\u003e    a=[  1 2 4; \r\n         4 5 5; \r\n         8 9 1];\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev=[4 5 1]\r\n\u003c/pre\u003e","function_template":"function y = i_th_largest(x)\r\n  \r\n\r\n%brute force is ugly\r\n\r\n\r\nend","test_suite":"%%\r\nx=[ 1 2 4; 4 5 5; 8 9 1];;\r\ny= [4 5 1];\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=ones(1000,1000);\r\ny=ones(1,1000);\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=zeros(1000,1000);\r\ny=zeros(1,1000);\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=eye(1000);\r\ny=[1 zeros(1,999)];\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=[ 1 1 3 4; 2 5 5 7; 8 8 8 8; 1 0 0 1];\r\ny= [4 5 8 0];\r\nassert(isequal(i_th_largest(x),y))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-06-03T16:41:30.000Z","updated_at":"2025-12-08T09:20:36.000Z","published_at":"2014-06-03T16:42:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    a=[  1 2 4; \\n         4 5 5; \\n         8 9 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\u003eOutput:\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=[4 5 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44436,"title":"Find the largest number","description":"Find the largest number |x| among 4 numbers given as variables |a|, |b|, |c|, and |d|.\r\n\r\nExample:\r\n\r\n  Input:  a = 4; b = 7; c = 1; d = 6;\r\n  Output: x = 7;\r\n\r\nYou must *NOT* use MATLAB built in functions such as min(), max() or sort()","description_html":"\u003cp\u003eFind the largest number \u003ctt\u003ex\u003c/tt\u003e among 4 numbers given as variables \u003ctt\u003ea\u003c/tt\u003e, \u003ctt\u003eb\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e, and \u003ctt\u003ed\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  a = 4; b = 7; c = 1; d = 6;\r\nOutput: x = 7;\r\n\u003c/pre\u003e\u003cp\u003eYou must \u003cb\u003eNOT\u003c/b\u003e use MATLAB built in functions such as min(), max() or sort()\u003c/p\u003e","function_template":"function x = largest(a, b, c, d)\r\n  x = a;\r\nend","test_suite":"%%\r\nfiletext = fileread('largest.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'max')),'max() forbidden')\r\nassert(isempty(strfind(filetext, 'min')),'min() forbidden')\r\nassert(isempty(strfind(filetext, 'sort')),'sort() forbidden')\r\nassert(isempty(strfind(filetext, 'unique')),'unique() forbidden')\r\n\r\n%%\r\na = 4; b = 7; c = 1; d = 6;\r\nx_correct = 7;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 1; d = 1;\r\nx_correct = 1;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 4; b = 3; c = 2; d = 1;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 2; c = 3; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 3; d = 5;\r\nx_correct = 5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 2; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 2; b = 3; c = 1; d = 6.5;\r\nx_correct = 6.5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 5; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 9; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 1; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":504,"test_suite_updated_at":"2020-05-13T19:39:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T12:39:01.000Z","updated_at":"2026-02-08T06:30:02.000Z","published_at":"2017-12-03T12:39:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the largest number\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e among 4 numbers given as variables\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,\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\u003eb\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: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\u003ec\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\u003ed\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\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:  a = 4; b = 7; c = 1; d = 6;\\nOutput: x = 7;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou must\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\u003eNOT\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use MATLAB built in functions such as min(), max() or sort()\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":45304,"title":"MinMax","description":"* x=[2 4 3 1 6 4 6]\r\n* output , y=[1 6 2 4 3]\r\n\r\nhere,y(1) is the minimum of x,\r\ny(2) is the maximum of x,\r\ny(3) is the 2nd minimum .. this way continue.\r\n\r\nx can be an array or a matrix.\r\n\r\ny is a row matrix.\r\n\r\n","description_html":"\u003cul\u003e\u003cli\u003ex=[2 4 3 1 6 4 6]\u003c/li\u003e\u003cli\u003eoutput , y=[1 6 2 4 3]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ehere,y(1) is the minimum of x,\r\ny(2) is the maximum of x,\r\ny(3) is the 2nd minimum .. this way continue.\u003c/p\u003e\u003cp\u003ex can be an array or a matrix.\u003c/p\u003e\u003cp\u003ey is a row matrix.\u003c/p\u003e","function_template":"function y = MinMax(x) \r\n  y = x;\r\nend","test_suite":"%%\r\nx=[2 4 3 1 6 4 6];\r\ny_correct = [1 6 2 4 3];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=magic(3);\r\ny_correct = [1     9     2     8     3     7     4     6     5];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nv=[-2,3,1]\r\nx=toeplitz(v);\r\ny_correct = [-2,3,1];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=[ 1 1 1 2 2 2 3 3 3 0 0 -3 -1 -2];\r\ny_correct = [-3     3    -2     2    -1     1     0];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=[zeros(4),ones(4)]\r\ny_correct = [0 1];\r\nassert(isequal(MinMax(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"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-02-01T18:21:12.000Z","updated_at":"2025-10-30T19:19:33.000Z","published_at":"2020-02-01T18:23: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[2 4 3 1 6 4 6]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput , y=[1 6 2 4 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ehere,y(1) is the minimum of x, y(2) is the maximum of x, y(3) is the 2nd minimum .. this way continue.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex can be an array or 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\u003ey is a row 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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\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\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y are\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\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\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":1107,"title":"Find max","description":"Find the maximum value of a given vector or matrix.","description_html":"\u003cp\u003eFind the maximum value of a given vector or matrix.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =  magic(5);\r\ny_correct = 25;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx =  [2 4 9 0 7 19;3 4 1 2 0 6];\r\ny_correct = 19;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx =  [2 4 9 0 7 19;3 4 1 2 0 6]';\r\ny_correct = 19;\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":45,"comments_count":8,"created_by":9099,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11711,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-12-08T02:44:41.000Z","updated_at":"2026-04-04T03:41:16.000Z","published_at":"2012-12-08T02:46:07.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\u003eFind the maximum value of a given vector or 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":42635,"title":"Maximum of each diagonal","description":"The well-known \u003chttp://www.mathworks.com/help/matlab/ref/max.html max\u003e function can operate along either the rows or the columns of a matrix by using\r\n\r\n  [Y,I] = max(X,[],1) or [Y,I] = max(X,[],2)\r\n\r\nbut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\r\n\r\n*Example*\r\n\r\nIf \r\n\r\n  X = magic(3) = [8 1 6\r\n                  3 5 7\r\n                  4 9 2]\r\n\r\nthen\r\n\r\n  Y = maxdiag(X) = [4 9 8 7 6]\r\n\r\nSee also \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42634-minimum-of-each-diagonal mindiag\u003e.","description_html":"\u003cp\u003eThe well-known \u003ca href = \"http://www.mathworks.com/help/matlab/ref/max.html\"\u003emax\u003c/a\u003e function can operate along either the rows or the columns of a matrix by using\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[Y,I] = max(X,[],1) or [Y,I] = max(X,[],2)\r\n\u003c/pre\u003e\u003cp\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eX = magic(3) = [8 1 6\r\n                3 5 7\r\n                4 9 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eY = maxdiag(X) = [4 9 8 7 6]\r\n\u003c/pre\u003e\u003cp\u003eSee also \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42634-minimum-of-each-diagonal\"\u003emindiag\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = maxdiag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isempty(maxdiag([])))\r\n\r\n%%\r\nx = randi(100);\r\nassert(isequal(maxdiag(x),x))\r\n\r\n%%\r\nx = randi(100,100,1);\r\nassert(isequal(maxdiag(x),x(end:-1:1)'))\r\n\r\n%%\r\nx = randi(100,1,100);\r\nassert(isequal(maxdiag(x),x))\r\n\r\n%%\r\nx = eye(2);\r\nassert(isequal(maxdiag(x),[0 1 0]))\r\n\r\n%%\r\nx = magic(3);\r\nassert(isequal(maxdiag(x),[4 9 8 7 6]))\r\n\r\n%%\r\nx = flipud(hankel(1:1000));\r\nassert(isequal(maxdiag(x),[1:1000,zeros(1,1000-1)]))\r\n\r\n%%\r\nx = toeplitz(1:1000);\r\nassert(isequal(maxdiag(x),[1000:-1:1,2:1000]))\r\n\r\n%%\r\nN = randi(1000);\r\nx = fliplr(toeplitz(1:N));\r\nassert(isequal(maxdiag(x),[1:N,N-1:-1:1]))\r\n\r\n%%\r\nx = magic(10);\r\nx = x(:,1:3);\r\nassert(isequal(maxdiag(x),[11 18 100 94 17 86 93 87 98 92 99 1]))\r\n\r\n%%\r\nx = hankel(-4:0,0:-2:-16);\r\nassert(isequal(maxdiag(x),[0 -1 0 -1 0 -1 0 -1 0 -2 -4 -6 -8]))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":24,"created_at":"2015-09-23T23:12:25.000Z","updated_at":"2026-04-01T07:14:21.000Z","published_at":"2015-09-23T23:12: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\u003eThe well-known\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/max.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emax\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e function can operate along either the rows or the columns of a matrix by using\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,I] = max(X,[],1) or [Y,I] = max(X,[],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\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw: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[X = magic(3) = [8 1 6\\n                3 5 7\\n                4 9 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\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[Y = maxdiag(X) = [4 9 8 7 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\u003eSee also\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/42634-minimum-of-each-diagonal\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emindiag\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":44100,"title":"Input \u0026 Output \"Smart One\"","description":"If i give my secret function a x value as input the result will be y value as output.\r\nExamples:\r\n\r\ninput: x=6 -----\u003e\u003e\u003e output: y= 12\r\n\r\ninput: x=111 -----\u003e\u003e\u003e output: y= 112\r\n\r\nNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them","description_html":"\u003cp\u003eIf i give my secret function a x value as input the result will be y value as output.\r\nExamples:\u003c/p\u003e\u003cp\u003einput: x=6 -----\u0026gt;\u0026gt;\u0026gt; output: y= 12\u003c/p\u003e\u003cp\u003einput: x=111 -----\u0026gt;\u0026gt;\u0026gt; output: y= 112\u003c/p\u003e\u003cp\u003eNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 6;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 10;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 18;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 18;\r\ny_correct = 22;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 22;\r\ny_correct = 30;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 30;\r\ny_correct = 36;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 36;\r\ny_correct = 42;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 42;\r\ny_correct = 46;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 1000;\r\ny_correct = 1008;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 9999999;\r\ny_correct = 9999990;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":37163,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2017-04-23T22:43:28.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-04-23T22:31:43.000Z","updated_at":"2026-03-15T13:08:27.000Z","published_at":"2017-04-23T22:43: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\",\"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 i give my secret function a x value as input the result will be y value as output. Examples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003einput: x=6 -----\u0026gt;\u0026gt;\u0026gt; output: y= 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003einput: x=111 -----\u0026gt;\u0026gt;\u0026gt; output: y= 112\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\u003eNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"errors":[],"problems":[{"id":44103,"title":"Find the maxmum value of N*N Matrix","description":"Input\r\n\r\nx=[1 2 3;\r\n4 5 6;\r\n 7 8 9]\r\n\r\noutput:\r\n\r\ny=9","description_html":"\u003cp\u003eInput\u003c/p\u003e\u003cp\u003ex=[1 2 3;\r\n4 5 6;\r\n 7 8 9]\u003c/p\u003e\u003cp\u003eoutput:\u003c/p\u003e\u003cp\u003ey=9\u003c/p\u003e","function_template":"function ans= your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =[1 2 3;\r\n4 9 6;\r\n 7 8 2];\r\ny_correct = 9;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =1;\r\ny_correct =1;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =[1 2 3];\r\ny_correct = 3;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx =[8 3;\r\n4 5;\r\n 7 1];\r\ny_correct = 8;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":37163,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":93,"test_suite_updated_at":"2017-05-08T12:40:42.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-04-25T09:29:42.000Z","updated_at":"2026-02-05T05:10:53.000Z","published_at":"2017-04-25T09:29:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput\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\u003eoutput:\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=9\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":44325,"title":"Matrix Max Finder","description":"Output the maximum value in a matrix","description_html":"\u003cp\u003eOutput the maximum value in a matrix\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = ...;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [3 7; 4 1];\r\ny_correct = 7;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":12852,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":123,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2017-09-14T17:14:14.000Z","updated_at":"2026-02-23T15:27:32.000Z","published_at":"2017-09-14T17:14:14.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eOutput the maximum value in a 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":42863,"title":"Replace values out of an interval with the lower or upper values","description":"For a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\r\n\r\nExample\r\n\r\n x= [1 2 3 4 5 1 2 4 6]\r\n\r\n n=[3,5]\r\n\r\n y_correct= [3 3 3 4 5 3 3 4 5]","description_html":"\u003cp\u003eFor a vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e x= [1 2 3 4 5 1 2 4 6]\u003c/pre\u003e\u003cpre\u003e n=[3,5]\u003c/pre\u003e\u003cpre\u003e y_correct= [3 3 3 4 5 3 3 4 5]\u003c/pre\u003e","function_template":"function y = limit2interval(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = ones(1,25);\r\nn=[0,2];\r\ny_correct = x;\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= [1 2 3 4 5 1 2 4 6];\r\nn=[3,5];\r\ny_correct= [3 3 3 4 5 3 3 4 5];\r\nassert(isequal(limit2interval(x,n),y_correct))\r\n\r\n%%\r\nx= magic(7);\r\nn=[7,14];\r\ny_correct=ones(7)*14-sparse([4 5 3 2 3 1 2 1 7 6 7 5 6],[1 1 2 3 3 4 4 5 5 6 6 7 7],[7 1 7 7 6 7 5 4 7 7 3 7 2])\r\nassert(isequal(limit2interval(x,n),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":55194,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":71,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2016-05-28T10:47:32.000Z","updated_at":"2026-02-04T15:47:26.000Z","published_at":"2016-05-28T21:13:31.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 vector or matrix X and an interval [n1,n2], the function replace every element of x inferior to n1 by n1, and every element of x superior to n2 by n2.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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= [1 2 3 4 5 1 2 4 6]\\n\\n n=[3,5]\\n\\n y_correct= [3 3 3 4 5 3 3 4 5]]]\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":1923,"title":"Find the maximum two numbers of every column of a matrix","description":"Find the maximum two numbers of every column of a matrix.\r\n\r\nExample:\r\n\r\nIf we input a matrix \r\n\r\n A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\r\n\r\nwe should get\r\n\r\n B = [ 6 2 5\r\n       4 1 4 ]\r\n","description_html":"\u003cp\u003eFind the maximum two numbers of every column of a matrix.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eIf we input a matrix\u003c/p\u003e\u003cpre\u003e A = [ 1 2 4\r\n       6 0 3\r\n       4 1 5 ]\u003c/pre\u003e\u003cp\u003ewe should get\u003c/p\u003e\u003cpre\u003e B = [ 6 2 5\r\n       4 1 4 ]\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4;\r\n     6 0 3;\r\n     4 1 5];\r\ny_correct = [6 2 5;\r\n             4 1 4];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = ones(3);\r\ny_correct = ones(2,3);\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = [ones(1,4); zeros(1,4)];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1:5;\r\n     6:10;\r\n     11:15;\r\n     16:20;\r\n     21:25];\r\ny_correct = [21:25; 16:20];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 5 7 3 47 2  3;\r\n     6 7 1 5 23 1 47;\r\n     7 1 3 2 68 4 11];\r\ny_correct = [7 7 7 5 68 4 47;\r\n             6 5 3 3 47 2 11];\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":1,"created_by":3668,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":231,"test_suite_updated_at":"2017-03-15T16:43:08.000Z","rescore_all_solutions":false,"group_id":21,"created_at":"2013-10-08T14:30:23.000Z","updated_at":"2026-03-31T17:07:39.000Z","published_at":"2013-10-08T14:30:22.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the maximum two numbers of every column of a matrix.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we input a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ A = [ 1 2 4\\n       6 0 3\\n       4 1 5 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ewe should get\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ B = [ 6 2 5\\n       4 1 4 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":45156,"title":" Find the max element of the array","description":" Find the max element of the array","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: 20.4333px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 10.2167px; transform-origin: 407px 10.2167px; vertical-align: baseline; \"\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 136px 8.5px; tab-size: 4; transform-origin: 136px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; perspective-origin: 24px 8.5px; transform-origin: 24px 8.5px; \"\u003e Find \u003c/span\u003e\u003cspan style=\"border-block-end-color: rgb(170, 4, 249); border-block-start-color: rgb(170, 4, 249); border-bottom-color: rgb(170, 4, 249); border-inline-end-color: rgb(170, 4, 249); border-inline-start-color: rgb(170, 4, 249); border-left-color: rgb(170, 4, 249); border-right-color: rgb(170, 4, 249); border-top-color: rgb(170, 4, 249); caret-color: rgb(170, 4, 249); color: rgb(170, 4, 249); column-rule-color: rgb(170, 4, 249); margin-inline-end: 0px; margin-right: 0px; outline-color: rgb(170, 4, 249); perspective-origin: 112px 8.5px; text-decoration-color: rgb(170, 4, 249); text-emphasis-color: rgb(170, 4, 249); transform-origin: 112px 8.5px; \"\u003ethe max element of the array\u003c/span\u003e\u003c/span\u003e\u003c/div\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 = [1 2 3 4];\r\ny_correct = 4;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [1 2 3 7 5 6];\r\ny_correct = 7;\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":6,"comments_count":3,"created_by":343758,"edited_by":223089,"edited_at":"2022-10-13T04:00:14.000Z","deleted_by":null,"deleted_at":null,"solvers_count":2222,"test_suite_updated_at":"2022-10-13T04:00:14.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2019-10-07T17:32:55.000Z","updated_at":"2026-04-03T16:12:01.000Z","published_at":"2019-10-07T17:32:55.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=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Find the max element of the array]]\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":58887,"title":"Neural Net: Best Index of Prediction array","description":"The final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\r\nFor the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction matrix.\r\nGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\r\n[case_peak,case_idx]=Prediction(P)\r\nif P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[3;2]\r\n","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: 234px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 117px; transform-origin: 407px 117px; 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: 379px 8px; transform-origin: 379px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\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: 379.5px 8px; transform-origin: 379.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eFor the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction matrix.\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: 378.5px 8px; transform-origin: 378.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\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: 113px 8px; transform-origin: 113px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003e[case_peak,case_idx]=Prediction(P)\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: 373px 8px; transform-origin: 373px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eif P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[3;2]\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 8px; transform-origin: 0px 8px; 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 [case_peak,case_idx]=Prediction(P)\r\n%P provides probability that an input is probably type n\r\n%P may represent [Prob_dog Prob_cat Prob_cow Prob_sheep] when trained on four anaimals\r\n%P may be a [1,n] prediction vector for a single case or\r\n%P may be an [m,n] prediction matrix of m cases\r\n case_peak=max(P);\r\n case_idx=find(P==max(P));\r\nend","test_suite":"%%\r\nvalid=1;\r\n%Binary functions AND/OR/XOR\r\n%input [0 0;0 1;1 0;1 1] cases\r\nPor=[.75 .25;.1 .9;.2 .8;.05 .95]; % [Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Por);\r\nif ~isequal(case_peak,max(Por,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Por,1)\r\n    if case_idx(i)~=find(Por(i,:)==max(Por(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\n%input [0 0;0 1;1 0;1 1] cases\r\nPand=[1 0;.8 0;.9 .1;.1 .9]; %[Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Pand);\r\nif ~isequal(case_peak,max(Pand,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Pand,1)\r\n    if case_idx(i)~=find(Pand(i,:)==max(Pand(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\nPxor=[.9 .2;.1 .8;.3 .8;.8 .1]; % [Prob-0 Prob-1] Notional values\r\n[case_peak,case_idx]=Prediction(Pxor);\r\nif ~isequal(case_peak,max(Pxor,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(Pxor,1)\r\n    if case_idx(i)~=find(Pxor(i,:)==max(Pxor(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\n\r\n\r\nassert(valid)\r\n%%\r\nvalid=1;\r\n%input [dog;cat;cow;sheep] cases\r\n%[Prob-dog Prob-cat Prob-cow Prob-sheep] Notional values\r\nP=[.8 .3 .2 .1;.3 .9 .2 .1;.1 .1 .7 .2;.25 .3 .1 .6]; \r\n[case_peak,case_idx]=Prediction(P);\r\nif ~isequal(case_peak,max(P,[],2))\r\n valid=0;\r\nend\r\nfor i=1:size(P,1)\r\n    if case_idx(i)~=find(P(i,:)==max(P(i,:)))\r\n     valid=0;\r\n    end\r\nend\r\n\r\nassert(valid)\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":3097,"edited_by":3097,"edited_at":"2023-08-19T23:47:40.000Z","deleted_by":null,"deleted_at":null,"solvers_count":18,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2023-08-19T22:24:20.000Z","updated_at":"2026-03-11T13:40:50.000Z","published_at":"2023-08-19T23:47:40.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 final ouput of a neural net application is a Prediction matrix/vector,P, that gives the probability of the input being of a set of N classes represented by the columns.\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 the XOR function the input matrix is [0 0;0 1;1 0;1 1] with an expected output vector of [0;1;1;0]. Ouput of Zero would be represented by a higher likelihood in column 1 than column 2 of the Prediction 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\u003eGiven a P matrix [m,n] where there are m cases and n possible outcomes return peak value for each case and the index of the most likely outcome.\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[case_peak,case_idx]=Prediction(P)\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 P was [0.1 0.5 0.9;0.2 0.8 0.4] (2 cases with 3 possible outcomes 1:3) return case_peak=[0.9;0.8] and case_idx=[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\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":1041,"title":"Find Index of maximum Value and maximum Value of a vector ","description":"Find the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\r\n\r\nExample:\r\n[1 2 5 7 5 7 4 3] Returns 7 and 4\r\n\r\n[1 4;2 3] Returns 4 and 2","description_html":"\u003cp\u003eFind the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\u003c/p\u003e\u003cp\u003eExample:\r\n[1 2 5 7 5 7 4 3] Returns 7 and 4\u003c/p\u003e\u003cp\u003e[1 4;2 3] Returns 4 and 2\u003c/p\u003e","function_template":"function [max_val, max_idx] = max_val_idx(x)\r\n  max_val=1;\r\n  max_idx=1;\r\nend","test_suite":"%%\r\nseq=randi(5,1,10);\r\nseq_max = max(seq);\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=rand(10);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=randn(10);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n%%\r\nseq=randi(2^15,128,1);\r\nseq_max = max(seq(:));\r\nseq_idx= find(seq==seq_max,1,'first');\r\n[max_val, max_idx] = max_val_idx(seq);\r\nassert(isequal(max_val,seq_max));\r\nassert(isequal(max_idx,seq_idx));\r\n\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":3097,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":168,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-11-20T04:15:52.000Z","updated_at":"2026-03-10T15:33:24.000Z","published_at":"2012-11-20T04:27: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\",\"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\u003eFind the Index of the first occurrence of the maximum value in a vector and also the maximum value in the vector.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample: [1 2 5 7 5 7 4 3] Returns 7 and 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\u003e[1 4;2 3] Returns 4 and 2\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":42630,"title":"Make visible max values","description":"Make visible maximum values of rows\r\n\r\n input = [1 2 3 4 5;\r\n          6 9 8 2 1;\r\n          2 1 4 5 8;\r\n          1 9 7 9 2];\r\n\r\n output = [0 0 0 0 5;\r\n           0 9 0 0 0;\r\n           0 0 0 0 8;\r\n           0 9 0 9 0];\r\n\r\nI prefer solutions without for/while loops","description_html":"\u003cp\u003eMake visible maximum values of rows\u003c/p\u003e\u003cpre\u003e input = [1 2 3 4 5;\r\n          6 9 8 2 1;\r\n          2 1 4 5 8;\r\n          1 9 7 9 2];\u003c/pre\u003e\u003cpre\u003e output = [0 0 0 0 5;\r\n           0 9 0 0 0;\r\n           0 0 0 0 8;\r\n           0 9 0 9 0];\u003c/pre\u003e\u003cp\u003eI prefer solutions without for/while loops\u003c/p\u003e","function_template":"function y = visibleMax(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 3 4 5;6 9 8 2 1;2 1 4 5 8;1 9 7 9 2];\r\ny_correct = [0 0 0 0 5;0 9 0 0 0;0 0 0 0 8;0 9 0 9 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n%%\r\nx = [10 20 40 85 96 15 14 12;14 15 12 16 19 17 15 0];\r\ny_correct = [0 0 0 0 96 0 0 0;0 0 0 0 19 0 0 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n\r\n%%\r\nx = [2 4 9; 9 1 0; 8 4 1; 7 5 6; 4 2 1; 4 5 6; 1 9 5];\r\ny_correct = [0 0 9;9 0 0;8 0 0;7 0 0;4 0 0;0 0 6;0 9 0];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n\r\n%%\r\nx = [5; 8 ; 9 ; 1 ; 3 ; 4]; \r\ny_correct = [5; 8 ; 9 ; 1 ; 3 ; 4];\r\nassert(isequal(visibleMax(x),y_correct))\r\n\r\n%%\r\nx =  [2 4; Inf 1; 9 2; NaN 5];\r\ny_correct =  [0 4;Inf 0;9 0;0 5];\r\nassert(isequal(visibleMax(x),y_correct))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":8703,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":46,"test_suite_updated_at":"2015-09-21T17:07:34.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2015-09-21T17:05:09.000Z","updated_at":"2025-12-07T21:01:10.000Z","published_at":"2015-09-21T17:05:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMake visible maximum values of rows\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ input = [1 2 3 4 5;\\n          6 9 8 2 1;\\n          2 1 4 5 8;\\n          1 9 7 9 2];\\n\\n output = [0 0 0 0 5;\\n           0 9 0 0 0;\\n           0 0 0 0 8;\\n           0 9 0 9 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\u003eI prefer solutions without for/while loops\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":2345,"title":"row-th maximum row elements","description":"Input a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\r\n\r\nExample: \r\n\r\nInput:\r\n\r\n    a=[  1 2 4; \r\n         4 5 5; \r\n         8 9 1];\r\n\r\nOutput:\r\n\r\n  v=[4 5 1]\r\n\r\n","description_html":"\u003cp\u003eInput a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cp\u003eInput:\u003c/p\u003e\u003cpre\u003e    a=[  1 2 4; \r\n         4 5 5; \r\n         8 9 1];\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ev=[4 5 1]\r\n\u003c/pre\u003e","function_template":"function y = i_th_largest(x)\r\n  \r\n\r\n%brute force is ugly\r\n\r\n\r\nend","test_suite":"%%\r\nx=[ 1 2 4; 4 5 5; 8 9 1];;\r\ny= [4 5 1];\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=ones(1000,1000);\r\ny=ones(1,1000);\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=zeros(1000,1000);\r\ny=zeros(1,1000);\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=eye(1000);\r\ny=[1 zeros(1,999)];\r\nassert(isequal(i_th_largest(x),y))\r\n\r\n%%\r\nx=[ 1 1 3 4; 2 5 5 7; 8 8 8 8; 1 0 0 1];\r\ny= [4 5 8 0];\r\nassert(isequal(i_th_largest(x),y))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":43,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2014-06-03T16:41:30.000Z","updated_at":"2025-12-08T09:20:36.000Z","published_at":"2014-06-03T16:42:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput a is a square matrix of size n*n. Output vector v is of size 1*n. The ith element of output v is the ith largest element of ith row of input matrix a. In case of a tie, take the ith member of the sorted elements.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eInput:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[    a=[  1 2 4; \\n         4 5 5; \\n         8 9 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\u003eOutput:\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=[4 5 1]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":44436,"title":"Find the largest number","description":"Find the largest number |x| among 4 numbers given as variables |a|, |b|, |c|, and |d|.\r\n\r\nExample:\r\n\r\n  Input:  a = 4; b = 7; c = 1; d = 6;\r\n  Output: x = 7;\r\n\r\nYou must *NOT* use MATLAB built in functions such as min(), max() or sort()","description_html":"\u003cp\u003eFind the largest number \u003ctt\u003ex\u003c/tt\u003e among 4 numbers given as variables \u003ctt\u003ea\u003c/tt\u003e, \u003ctt\u003eb\u003c/tt\u003e, \u003ctt\u003ec\u003c/tt\u003e, and \u003ctt\u003ed\u003c/tt\u003e.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eInput:  a = 4; b = 7; c = 1; d = 6;\r\nOutput: x = 7;\r\n\u003c/pre\u003e\u003cp\u003eYou must \u003cb\u003eNOT\u003c/b\u003e use MATLAB built in functions such as min(), max() or sort()\u003c/p\u003e","function_template":"function x = largest(a, b, c, d)\r\n  x = a;\r\nend","test_suite":"%%\r\nfiletext = fileread('largest.m');\r\nassert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')\r\nassert(isempty(strfind(filetext, 'max')),'max() forbidden')\r\nassert(isempty(strfind(filetext, 'min')),'min() forbidden')\r\nassert(isempty(strfind(filetext, 'sort')),'sort() forbidden')\r\nassert(isempty(strfind(filetext, 'unique')),'unique() forbidden')\r\n\r\n%%\r\na = 4; b = 7; c = 1; d = 6;\r\nx_correct = 7;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 1; d = 1;\r\nx_correct = 1;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 4; b = 3; c = 2; d = 1;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 2; c = 3; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 1; b = 1; c = 3; d = 5;\r\nx_correct = 5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 2; d = 4;\r\nx_correct = 4;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 2; b = 3; c = 1; d = 6.5;\r\nx_correct = 6.5;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 5; b = 3; c = 3; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 3; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 9; d = 9;\r\nx_correct = 9;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n\r\n%%\r\na = 3; b = 3; c = 1; d = 1;\r\nx_correct = 3;\r\nassert(isequal(largest(a, b, c, d),x_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":140356,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":504,"test_suite_updated_at":"2020-05-13T19:39:30.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-12-03T12:39:01.000Z","updated_at":"2026-02-08T06:30:02.000Z","published_at":"2017-12-03T12:39:01.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eFind the largest number\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\u003ex\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e among 4 numbers given as variables\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,\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\u003eb\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: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\u003ec\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\u003ed\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\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:  a = 4; b = 7; c = 1; d = 6;\\nOutput: x = 7;]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou must\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\u003eNOT\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e use MATLAB built in functions such as min(), max() or sort()\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":45304,"title":"MinMax","description":"* x=[2 4 3 1 6 4 6]\r\n* output , y=[1 6 2 4 3]\r\n\r\nhere,y(1) is the minimum of x,\r\ny(2) is the maximum of x,\r\ny(3) is the 2nd minimum .. this way continue.\r\n\r\nx can be an array or a matrix.\r\n\r\ny is a row matrix.\r\n\r\n","description_html":"\u003cul\u003e\u003cli\u003ex=[2 4 3 1 6 4 6]\u003c/li\u003e\u003cli\u003eoutput , y=[1 6 2 4 3]\u003c/li\u003e\u003c/ul\u003e\u003cp\u003ehere,y(1) is the minimum of x,\r\ny(2) is the maximum of x,\r\ny(3) is the 2nd minimum .. this way continue.\u003c/p\u003e\u003cp\u003ex can be an array or a matrix.\u003c/p\u003e\u003cp\u003ey is a row matrix.\u003c/p\u003e","function_template":"function y = MinMax(x) \r\n  y = x;\r\nend","test_suite":"%%\r\nx=[2 4 3 1 6 4 6];\r\ny_correct = [1 6 2 4 3];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=magic(3);\r\ny_correct = [1     9     2     8     3     7     4     6     5];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nv=[-2,3,1]\r\nx=toeplitz(v);\r\ny_correct = [-2,3,1];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=[ 1 1 1 2 2 2 3 3 3 0 0 -3 -1 -2];\r\ny_correct = [-3     3    -2     2    -1     1     0];\r\nassert(isequal(MinMax(x),y_correct))\r\n%%\r\nx=[zeros(4),ones(4)]\r\ny_correct = [0 1];\r\nassert(isequal(MinMax(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":363598,"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-02-01T18:21:12.000Z","updated_at":"2025-10-30T19:19:33.000Z","published_at":"2020-02-01T18:23: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=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex=[2 4 3 1 6 4 6]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eoutput , y=[1 6 2 4 3]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ehere,y(1) is the minimum of x, y(2) is the maximum of x, y(3) is the 2nd minimum .. this way continue.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ex can be an array or 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\u003ey is a row 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":45394,"title":"Count the number of folds needed to pack a large sheet","description":"In a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\r\n\r\n# Lay down a large sheet of paper of size X-by-Y feet.\r\n# _Fold_ the sheet in half so that the _larger_ length between X and Y is halved and the other length remains the same.\r\n# Repeat step 2 until _both_ lengths X and Y are _less_ than 1 foot.\r\n\r\nFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u003c= X \u003c= 4000 and 1 \u003c= Y \u003c= 4000. \r\n\r\nAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u003e (4,2.5) -\u003e (2,2.5) -\u003e (2,1.25) -\u003e (1,1.25) -\u003e (1,0.625) -\u003e (0.5,0.625). We stop because _both_ sizes are now less than 1. This takes a total of 6 folds.","description_html":"\u003cp\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/p\u003e\u003col\u003e\u003cli\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/li\u003e\u003cli\u003e\u003ci\u003eFold\u003c/i\u003e the sheet in half so that the \u003ci\u003elarger\u003c/i\u003e length between X and Y is halved and the other length remains the same.\u003c/li\u003e\u003cli\u003eRepeat step 2 until \u003ci\u003eboth\u003c/i\u003e lengths X and Y are \u003ci\u003eless\u003c/i\u003e than 1 foot.\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eFor this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/p\u003e\u003cp\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because \u003ci\u003eboth\u003c/i\u003e sizes are now less than 1. This takes a total of 6 folds.\u003c/p\u003e","function_template":"function y = number_of_folds(X,Y)\r\n  y = X;\r\nend","test_suite":"%%\r\nassert(isequal(number_of_folds(3247,2132),24))\r\n%%\r\nassert(isequal(number_of_folds(1403,3757),23))\r\n%%\r\nassert(isequal(number_of_folds(3504,2201),24))\r\n%%\r\nassert(isequal(number_of_folds(2490,2349),24))\r\n%%\r\nassert(isequal(number_of_folds(831,1205),21))\r\n%%\r\nassert(isequal(number_of_folds(1884,922),21))\r\n%%\r\nassert(isequal(number_of_folds(2,4),5))\r\n%%\r\nassert(isequal(number_of_folds(3378,780),22))\r\n%%\r\nassert(isequal(number_of_folds(904,683),20))\r\n%%\r\nassert(isequal(number_of_folds(911,1743),21))\r\n%%\r\nassert(isequal(number_of_folds(1245,3694),23))\r\n%%\r\nassert(isequal(number_of_folds(1721,740),21))\r\n%%\r\nassert(isequal(number_of_folds(3620,3919),24))\r\n%%\r\nassert(isequal(number_of_folds(1756,445),20))\r\n%%\r\nassert(isequal(number_of_folds(1033,1635),22))\r\n%%\r\nassert(isequal(number_of_folds(2380,1049),23))\r\n%%\r\nassert(isequal(number_of_folds(2412,2845),24))\r\n%%\r\nassert(isequal(number_of_folds(887,470),19))\r\n%%\r\nassert(isequal(number_of_folds(1187,1276),22))\r\n%%\r\nassert(isequal(number_of_folds(1697,2032),22))\r\n%%\r\nassert(isequal(number_of_folds(343,1050),20))\r\n%%\r\nassert(isequal(number_of_folds(3205,117),19))\r\n%%\r\nassert(isequal(number_of_folds(3716,2922),24))\r\n%%\r\nassert(isequal(number_of_folds(1955,2315),23))\r\n%%\r\nassert(isequal(number_of_folds(950,1836),21))\r\n%%\r\nassert(isequal(number_of_folds(3853,2188),24))\r\n%%\r\nassert(isequal(number_of_folds(2085,927),22))\r\n%%\r\nassert(isequal(number_of_folds(1956,2497),23))\r\n%%\r\nassert(isequal(number_of_folds(2717,1583),23))\r\n%%\r\nassert(isequal(number_of_folds(1470,3952),23))\r\n%%\r\nassert(isequal(number_of_folds(151,3541),20))\r\n%%\r\nassert(isequal(number_of_folds(3654,3185),24))\r\n%%\r\nassert(isequal(number_of_folds(395,1048),20))\r\n%%\r\nassert(isequal(number_of_folds(1342,2719),23))\r\n%%\r\nassert(isequal(number_of_folds(547,2885),22))\r\n%%\r\nassert(isequal(number_of_folds(428,2616),21))\r\n%%\r\nassert(isequal(number_of_folds(1977,3117),23))\r\n%%\r\nassert(isequal(number_of_folds(2861,3615),24))\r\n%%\r\nassert(isequal(number_of_folds(3564,1337),23))\r\n%%\r\nassert(isequal(number_of_folds(1,4000),13))\r\n%%\r\nassert(isequal(number_of_folds(2795,792),22))\r\n%%\r\nassert(isequal(number_of_folds(123,2977),19))\r\n%%\r\nassert(isequal(number_of_folds(2001,1920),22))\r\n%%\r\nassert(isequal(number_of_folds(3619,2440),24))\r\n%%\r\nassert(isequal(number_of_folds(2471,3438),24))\r\n%%\r\nassert(isequal(number_of_folds(3222,2307),24))\r\n%%\r\nassert(isequal(number_of_folds(732,960),20))\r\n%%\r\nassert(isequal(number_of_folds(3547,115),19))\r\n%%\r\nassert(isequal(number_of_folds(1960,672),21))\r\n%%\r\nassert(isequal(number_of_folds(3915,2851),24))\r\n%%\r\nassert(isequal(number_of_folds(2002,1885),22))\r\n%%\r\nassert(isequal(number_of_folds(239,2728),20))\r\n%%\r\nassert(isequal(number_of_folds(170,286),17))\r\n%%\r\nassert(isequal(number_of_folds(2087,387),21))\r\n%%\r\nassert(isequal(number_of_folds(3273,3271),24))\r\n%%\r\nassert(isequal(number_of_folds(2890,600),22))\r\n%%\r\nassert(isequal(number_of_folds(2639,2075),24))\r\n%%\r\nassert(isequal(number_of_folds(3892,2596),24))\r\n%%\r\nassert(isequal(number_of_folds(3202,1816),23))\r\n%%\r\nassert(isequal(number_of_folds(1730,3302),23))\r\n%%\r\nassert(isequal(number_of_folds(334,533),19))\r\n%%\r\nassert(isequal(number_of_folds(694,1564),21))\r\n%%\r\nassert(isequal(number_of_folds(3326,3214),24))\r\n%%\r\nassert(isequal(number_of_folds(242,1598),19))\r\n%%\r\nassert(isequal(number_of_folds(2108,1668),23))\r\n%%\r\nassert(isequal(number_of_folds(2628,2512),24))\r\n%%\r\nassert(isequal(number_of_folds(1168,1727),22))\r\n%%\r\nassert(isequal(number_of_folds(62,3937),18))\r\n%%\r\nassert(isequal(number_of_folds(669,425),19))\r\n%%\r\nassert(isequal(number_of_folds(1490,793),21))\r\n%%\r\nassert(isequal(number_of_folds(1959,1358),22))\r\n%%\r\nassert(isequal(number_of_folds(3807,3682),24))\r\n%%\r\nassert(isequal(number_of_folds(211,2952),20))\r\n%%\r\nassert(isequal(number_of_folds(1077,1692),22))\r\n%%\r\nassert(isequal(number_of_folds(2192,3771),24))\r\n%%\r\nassert(isequal(number_of_folds(1,1),2))\r\n%%\r\nassert(isequal(number_of_folds(1671,3933),23))\r\n%%\r\nassert(isequal(number_of_folds(1206,2805),23))\r\n%%\r\nassert(isequal(number_of_folds(2666,2157),24))\r\n%%\r\nassert(isequal(number_of_folds(2793,2667),24))\r\n%%\r\nassert(isequal(number_of_folds(713,513),20))\r\n%%\r\nassert(isequal(number_of_folds(3997,685),22))\r\n%%\r\nassert(isequal(number_of_folds(131,2245),20))\r\n%%\r\nassert(isequal(number_of_folds(3528,2677),24))\r\n%%\r\nassert(isequal(number_of_folds(762,1476),21))\r\n%%\r\nassert(isequal(number_of_folds(1843,3927),23))\r\n%%\r\nassert(isequal(number_of_folds(626,3423),22))\r\n%%\r\nassert(isequal(number_of_folds(2580,1506),23))\r\n%%\r\nassert(isequal(number_of_folds(764,1714),21))\r\n%%\r\nassert(isequal(number_of_folds(1929,483),20))\r\n%%\r\nassert(isequal(number_of_folds(2359,905),22))\r\n%%\r\nassert(isequal(number_of_folds(1539,2332),23))\r\n%%\r\nassert(isequal(number_of_folds(1008,1162),21))\r\n%%\r\nassert(isequal(number_of_folds(2469,1062),23))\r\n%%\r\nassert(isequal(number_of_folds(15,15),8))\r\n%%\r\nassert(isequal(number_of_folds(3298,3931),24))\r\n%%\r\nassert(isequal(number_of_folds(2921,1376),23))\r\n%%\r\nassert(isequal(number_of_folds(2337,432),21))\r\n%%\r\nassert(isequal(number_of_folds(3626,3519),24))\r\n%%\r\nassert(isequal(number_of_folds(3272,1043),23))\r\n%%\r\nassert(isequal(number_of_folds(3,2),4))\r\n%%\r\nassert(isequal(number_of_folds(2378,91),19))\r\n%%\r\nassert(isequal(number_of_folds(1702,1251),22))\r\n%%\r\nassert(isequal(number_of_folds(646,716),20))\r\n%%\r\nassert(isequal(number_of_folds(1692,377),20))\r\n%%\r\nassert(isequal(number_of_folds(16,15),9))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":3,"created_by":255320,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":115,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2020-03-26T22:22:34.000Z","updated_at":"2026-03-31T14:22:20.000Z","published_at":"2020-03-26T22:22:34.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIn a certain paper factory, large sheets of paper are being made every day. Before sending the sheets for shipment, they have to be packed in a small case of length 1 foot and width 1 foot. This is done automatically by a robot, which is programmed to fold a large sheet of paper as many times as needed to fit it into the case. The following is the robot's algorithm:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eLay down a large sheet of paper of size X-by-Y feet.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eFold\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e the sheet in half so that the\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\u003elarger\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e length between X and Y is halved and the other length remains the same.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"2\\\"/\u003e\u003c/w:numPr\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRepeat step 2 until\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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e lengths X and Y are\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\u003eless\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e than 1 foot.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 this problem, you can assume that the thickness of the paper is irrelevant. You are then given the following task by the company manager: Write a function that determines the number of folds needed to pack a certain sheet of paper, given its initial dimensions X and Y. You are ensured that X and Y are integers given in feet, and that 1 \u0026lt;= X \u0026lt;= 4000 and 1 \u0026lt;= Y \u0026lt;= 4000.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAs an example, let the initial dimensions be (X,Y) = (4,5). The algorithm will produce the following sequence of paper sizes: (4,5) -\u0026gt; (4,2.5) -\u0026gt; (2,2.5) -\u0026gt; (2,1.25) -\u0026gt; (1,1.25) -\u0026gt; (1,0.625) -\u0026gt; (0.5,0.625). We stop because\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\u003eboth\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e sizes are now less than 1. This takes a total of 6 folds.\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":1107,"title":"Find max","description":"Find the maximum value of a given vector or matrix.","description_html":"\u003cp\u003eFind the maximum value of a given vector or matrix.\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =  magic(5);\r\ny_correct = 25;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx =  [2 4 9 0 7 19;3 4 1 2 0 6];\r\ny_correct = 19;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx =  [2 4 9 0 7 19;3 4 1 2 0 6]';\r\ny_correct = 19;\r\nassert(isequal(your_fcn_name(x),y_correct))","published":true,"deleted":false,"likes_count":45,"comments_count":8,"created_by":9099,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":11711,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":1,"created_at":"2012-12-08T02:44:41.000Z","updated_at":"2026-04-04T03:41:16.000Z","published_at":"2012-12-08T02:46:07.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\u003eFind the maximum value of a given vector or 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":42635,"title":"Maximum of each diagonal","description":"The well-known \u003chttp://www.mathworks.com/help/matlab/ref/max.html max\u003e function can operate along either the rows or the columns of a matrix by using\r\n\r\n  [Y,I] = max(X,[],1) or [Y,I] = max(X,[],2)\r\n\r\nbut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\r\n\r\n*Example*\r\n\r\nIf \r\n\r\n  X = magic(3) = [8 1 6\r\n                  3 5 7\r\n                  4 9 2]\r\n\r\nthen\r\n\r\n  Y = maxdiag(X) = [4 9 8 7 6]\r\n\r\nSee also \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42634-minimum-of-each-diagonal mindiag\u003e.","description_html":"\u003cp\u003eThe well-known \u003ca href = \"http://www.mathworks.com/help/matlab/ref/max.html\"\u003emax\u003c/a\u003e function can operate along either the rows or the columns of a matrix by using\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e[Y,I] = max(X,[],1) or [Y,I] = max(X,[],2)\r\n\u003c/pre\u003e\u003cp\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eX = magic(3) = [8 1 6\r\n                3 5 7\r\n                4 9 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eY = maxdiag(X) = [4 9 8 7 6]\r\n\u003c/pre\u003e\u003cp\u003eSee also \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42634-minimum-of-each-diagonal\"\u003emindiag\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = maxdiag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nassert(isempty(maxdiag([])))\r\n\r\n%%\r\nx = randi(100);\r\nassert(isequal(maxdiag(x),x))\r\n\r\n%%\r\nx = randi(100,100,1);\r\nassert(isequal(maxdiag(x),x(end:-1:1)'))\r\n\r\n%%\r\nx = randi(100,1,100);\r\nassert(isequal(maxdiag(x),x))\r\n\r\n%%\r\nx = eye(2);\r\nassert(isequal(maxdiag(x),[0 1 0]))\r\n\r\n%%\r\nx = magic(3);\r\nassert(isequal(maxdiag(x),[4 9 8 7 6]))\r\n\r\n%%\r\nx = flipud(hankel(1:1000));\r\nassert(isequal(maxdiag(x),[1:1000,zeros(1,1000-1)]))\r\n\r\n%%\r\nx = toeplitz(1:1000);\r\nassert(isequal(maxdiag(x),[1000:-1:1,2:1000]))\r\n\r\n%%\r\nN = randi(1000);\r\nx = fliplr(toeplitz(1:N));\r\nassert(isequal(maxdiag(x),[1:N,N-1:-1:1]))\r\n\r\n%%\r\nx = magic(10);\r\nx = x(:,1:3);\r\nassert(isequal(maxdiag(x),[11 18 100 94 17 86 93 87 98 92 99 1]))\r\n\r\n%%\r\nx = hankel(-4:0,0:-2:-16);\r\nassert(isequal(maxdiag(x),[0 -1 0 -1 0 -1 0 -1 0 -2 -4 -6 -8]))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":67,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":24,"created_at":"2015-09-23T23:12:25.000Z","updated_at":"2026-04-01T07:14:21.000Z","published_at":"2015-09-23T23:12: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\u003eThe well-known\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/help/matlab/ref/max.html\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emax\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e function can operate along either the rows or the columns of a matrix by using\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,I] = max(X,[],1) or [Y,I] = max(X,[],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\u003ebut it cannot operate along a diagonal dimension. For this problem, create a function that returns the largest component along each diagonal of a matrix (starting with the one-element diagonal in the bottom left corner of the matrix).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw: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[X = magic(3) = [8 1 6\\n                3 5 7\\n                4 9 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\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[Y = maxdiag(X) = [4 9 8 7 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\u003eSee also\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/42634-minimum-of-each-diagonal\\\"\u003e\u003cw:r\u003e\u003cw:t\u003emindiag\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":44100,"title":"Input \u0026 Output \"Smart One\"","description":"If i give my secret function a x value as input the result will be y value as output.\r\nExamples:\r\n\r\ninput: x=6 -----\u003e\u003e\u003e output: y= 12\r\n\r\ninput: x=111 -----\u003e\u003e\u003e output: y= 112\r\n\r\nNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them","description_html":"\u003cp\u003eIf i give my secret function a x value as input the result will be y value as output.\r\nExamples:\u003c/p\u003e\u003cp\u003einput: x=6 -----\u0026gt;\u0026gt;\u0026gt; output: y= 12\u003c/p\u003e\u003cp\u003einput: x=111 -----\u0026gt;\u0026gt;\u0026gt; output: y= 112\u003c/p\u003e\u003cp\u003eNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them\u003c/p\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = 6;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 1;\r\ny_correct = 10;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 10;\r\ny_correct = 18;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 18;\r\ny_correct = 22;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 22;\r\ny_correct = 30;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 30;\r\ny_correct = 36;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 36;\r\ny_correct = 42;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 42;\r\ny_correct = 46;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 1000;\r\ny_correct = 1008;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n%%\r\nx = 9999999;\r\ny_correct = 9999990;\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":0,"comments_count":1,"created_by":37163,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":17,"test_suite_updated_at":"2017-04-23T22:43:28.000Z","rescore_all_solutions":false,"group_id":1,"created_at":"2017-04-23T22:31:43.000Z","updated_at":"2026-03-15T13:08:27.000Z","published_at":"2017-04-23T22:43: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\",\"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 i give my secret function a x value as input the result will be y value as output. Examples:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003einput: x=6 -----\u0026gt;\u0026gt;\u0026gt; output: y= 12\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003einput: x=111 -----\u0026gt;\u0026gt;\u0026gt; output: y= 112\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\u003eNb: *Test Suite are inputs and outputs so don't submit an answer without refer to them\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"term":"tag:\"max\"","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:\"max\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"max\"","","\"","max","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4a01959938\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f4a01959898\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4a01958c18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4a01959bb8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4a01959b18\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4a01959a78\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4a019599d8\u003e":"tag:\"max\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4a019599d8\u003e":"tag:\"max\""},"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:\"max\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"tag":[["tag:\"max\"","","\"","max","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007f4a01959938\u003e":null,"#\u003cMathWorks::Search::Field:0x00007f4a01959898\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007f4a01958c18\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007f4a01959bb8\u003e":1,"#\u003cMathWorks::Search::Field:0x00007f4a01959b18\u003e":50,"#\u003cMathWorks::Search::Field:0x00007f4a01959a78\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007f4a019599d8\u003e":"tag:\"max\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007f4a019599d8\u003e":"tag:\"max\""},"queried_facets":{}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":44103,"difficulty_rating":"easy"},{"id":44325,"difficulty_rating":"easy"},{"id":42863,"difficulty_rating":"easy"},{"id":1923,"difficulty_rating":"easy"},{"id":45156,"difficulty_rating":"easy"},{"id":58887,"difficulty_rating":"easy"},{"id":1041,"difficulty_rating":"easy"},{"id":42630,"difficulty_rating":"easy-medium"},{"id":2345,"difficulty_rating":"easy-medium"},{"id":44436,"difficulty_rating":"easy-medium"},{"id":45304,"difficulty_rating":"easy-medium"},{"id":45394,"difficulty_rating":"easy-medium"},{"id":1107,"difficulty_rating":"easy-medium"},{"id":42635,"difficulty_rating":"easy-medium"},{"id":44100,"difficulty_rating":"medium"}]}}