{"group":{"id":1,"name":"Community","lockable":false,"created_at":"2012-01-18T18:02:15.000Z","updated_at":"2026-05-26T00:16:20.000Z","description":"Problems submitted by members of the MATLAB Central community.","is_default":true,"created_by":161519,"badge_id":null,"featured":false,"trending":false,"solution_count_in_trending_period":0,"trending_last_calculated":"2026-05-26T00: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":2560,"title":"expand intervals vol.2","description":"Similar to problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\r\n\r\nGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\r\n\r\nSee also problems \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2561 2561\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e.","description_html":"\u003cp\u003eSimilar to problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\u003c/p\u003e\u003cp\u003eSee also problems \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2561\"\u003e2561\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(x);\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 100 300];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:9; -9:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":124,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T09:17:06.000Z","updated_at":"2026-04-07T19:13:26.000Z","published_at":"2014-09-08T09:17:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also problems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2561\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2561\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2528,"title":"expand intervals","description":"You're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.","description_html":"\u003cp\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.\u003c/p\u003e","function_template":"function elements = ExpandIntervals(bounds)\r\n  elements = -Inf:Inf;\r\nend","test_suite":"%%\r\nbounds = [1 5 7 9 24 32];\r\nelements = [1 2 3 4 5 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [9 9 11 11];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [100 200 300 400];\r\nelements = [100:200 300:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:10; -10:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":165,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-08-25T07:54:09.000Z","updated_at":"2026-02-16T09:30:57.000Z","published_at":"2014-08-25T07:54:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, within these intervals.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2561,"title":"expand intervals vol.3","description":"This is the next problem after \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2560 2560\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\r\n\r\nGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\r\n\r\nSee also problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e","description_html":"\u003cp\u003eThis is the next problem after \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2560\"\u003e2560\u003c/a\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\u003c/p\u003e\u003cp\u003eSee also problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(round(x));\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [5 1 3 9 32 24];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 300 100];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.1:9; -9:9.5];\r\nbounds = temp(:)';\r\nelements = -11:9;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.21:11; -8.7:10];\r\nbounds = temp(:)';\r\nelements = [-11:0, 7:10];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:2.599:9; -9:2.601:11];\r\nbounds = temp(:)';\r\nelements = [-11:-7, -5:-2, 0:6, 8:9];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10.8 10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) \r\n\r\n%%\r\nbounds = [10.8 -10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) ","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":83,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T10:51:42.000Z","updated_at":"2026-05-05T01:30:34.000Z","published_at":"2014-09-08T10:51:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next problem after\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2560\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2560\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"problem_search":{"problems":[{"id":2560,"title":"expand intervals vol.2","description":"Similar to problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\r\n\r\nGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\r\n\r\nSee also problems \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2561 2561\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e.","description_html":"\u003cp\u003eSimilar to problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\u003c/p\u003e\u003cp\u003eSee also problems \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2561\"\u003e2561\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e.\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(x);\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 100 300];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:9; -9:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":0,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":124,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T09:17:06.000Z","updated_at":"2026-04-07T19:13:26.000Z","published_at":"2014-09-08T09:17:06.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. This is a more general case, when bounds creates intersections between intervals. Description changes just a little bit from the original:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a row vector of an even number of integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also problems\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2561\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2561\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2528,"title":"expand intervals","description":"You're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.","description_html":"\u003cp\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered,  within these intervals.\u003c/p\u003e","function_template":"function elements = ExpandIntervals(bounds)\r\n  elements = -Inf:Inf;\r\nend","test_suite":"%%\r\nbounds = [1 5 7 9 24 32];\r\nelements = [1 2 3 4 5 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [9 9 11 11];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [100 200 300 400];\r\nelements = [100:200 300:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-10:10; -10:10];\r\nbounds = temp(:)';\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10 10];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":999,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":165,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-08-25T07:54:09.000Z","updated_at":"2026-02-16T09:30:57.000Z","published_at":"2014-08-25T07:54:09.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou're given a row vector of an even number of monotonically increasing integers. Each pair of consecutive integers is the lower and upper bound (included) of an integer interval. Return a row vector which consists of all the integers, ordered, within these intervals.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":2561,"title":"expand intervals vol.3","description":"This is the next problem after \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2528 2528\u003e and \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/2560 2560\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\r\n\r\nGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\r\n\r\nSee also problem \u003chttp://www.mathworks.co.uk/matlabcentral/cody/problems/1986 1986\u003e","description_html":"\u003cp\u003eThis is the next problem after \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\"\u003e2528\u003c/a\u003e and \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/2560\"\u003e2560\u003c/a\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\u003c/p\u003e\u003cp\u003eGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\u003c/p\u003e\u003cp\u003eSee also problem \u003ca href = \"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\"\u003e1986\u003c/a\u003e\u003c/p\u003e","function_template":"function y = ExpandIntervals(x)\r\n  y = sort(round(x));\r\nend","test_suite":"%%\r\nbounds = [1 5 3 9 24 32];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [5 1 3 9 32 24];\r\nelements = [1 2 3 4 5 6 7 8 9 24 25 26 27 28 29 30 31 32];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [11 11 9 9];\r\nelements = [9 11];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [200 400 300 100];\r\nelements = [100:400];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.1:9; -9:9.5];\r\nbounds = temp(:)';\r\nelements = -11:9;\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:1.21:11; -8.7:10];\r\nbounds = temp(:)';\r\nelements = [-11:0, 7:10];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\ntemp = [-11:2.599:9; -9:2.601:11];\r\nbounds = temp(:)';\r\nelements = [-11:-7, -5:-2, 0:6, 8:9];\r\nassert(isequal(ExpandIntervals(bounds),elements))\r\n\r\n%%\r\nbounds = [-10.8 10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) \r\n\r\n%%\r\nbounds = [10.8 -10.9];\r\nelements = -10:10;\r\nassert(isequal(ExpandIntervals(bounds),elements)) ","published":true,"deleted":false,"likes_count":1,"comments_count":4,"created_by":14358,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":83,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":21,"created_at":"2014-09-08T10:51:42.000Z","updated_at":"2026-05-05T01:30:34.000Z","published_at":"2014-09-08T10:51:42.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThis is the next problem after\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2528\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2528\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e and\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/2560\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e2560\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. It is a more general case, when bounds creates intersections between intervals. Description changes as follow:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a row vector of an even number of scalars. Each pair create bounds of an interval but their occurence may vary. Return a row vector which consists of all the integers, ordered, non repeated, within these intervals (union of integer intervals).\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSee also problem\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.co.uk/matlabcentral/cody/problems/1986\\\"\u003e\u003cw:r\u003e\u003cw:t\u003e1986\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"}],"errors":[],"facets":[[{"value":"Indexing III","count":3,"selected":false}],[{"value":"medium","count":3,"selected":false}]],"term":"tag:\"integer interval\"","page":1,"per_page":50,"sort":"map(difficulty_value,0,0,999) asc"}}