{"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":1321,"title":"Given a matrix, swap the 2nd \u0026 3rd columns","description":"If\r\n\r\n a = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];\r\n\r\nthen the result is\r\n\r\n ans =\r\n\r\n     1     3     2     4\r\n     1     3     2     4\r\n     1     3     2     4\r\n     1     3     2     4\r\n\r\nPerform a simple swap of the two middle columns.","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: 266.467px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 133.233px; transform-origin: 407px 133.233px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.5px 8px; transform-origin: 3.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ea = [1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ethen the result is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans = [1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 64px 8.5px; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 95px 8px; transform-origin: 95px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eby swapping columns 2 and 3.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = swapmid(x)\r\n  y = 'swap';\r\nend","test_suite":"%%\r\nx =         [1 2 3 4;1 2 3 4;1 2 3 4;1 2 3 4];\r\ny_correct = [1 3 2 4;1 3 2 4;1 3 2 4;1 3 2 4];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [1 2 3 4;5 6 7 8;1 2 3 4;5 6 7 8];\r\ny_correct = [1 3 2 4;5 7 6 8;1 3 2 4;5 7 6 8];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         ones(5,3);\r\ny_correct = x;\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         eye(5);\r\ny_correct = [1 0 0 0 0; 0 0 1 0 0; 0 1 0 0 0; 0 0 0 1 0; 0 0 0 0 1];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [1:7; 2:8; 3:9];\r\ny_correct = [1 3 2 4:7; 2 4 3 5:8; 3 5 4 6:9];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [ones(10,1),zeros(10,1),5*ones(10,1)];\r\ny_correct = [ones(10,1),5*ones(10,1),zeros(10,1)];\r\nassert(isequal(swapmid(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":11,"comments_count":7,"created_by":6975,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1265,"test_suite_updated_at":"2017-04-06T17:19:25.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-03-07T05:26:33.000Z","updated_at":"2026-04-02T09:37:04.000Z","published_at":"2013-03-07T05:26:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a = [1 2 3 4;\\n     1 2 3 4;\\n     1 2 3 4;\\n     1 2 3 4];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen the result is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ans = [1 3 2 4\\n       1 3 2 4\\n       1 3 2 4\\n       1 3 2 4];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eby swapping columns 2 and 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2178,"title":"Matrix multiplication across rows","description":"Given matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\r\n\r\nExample\r\n \r\n m = [ 1 2 3\r\n       4 5 6\r\n       7 8 9 ]\r\n\r\nThen\r\n\r\n n = [ 1   2    6\r\n       4  20  120\r\n       7  56  504 ]\r\n\r\n","description_html":"\u003cp\u003eGiven matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e m = [ 1 2 3\r\n       4 5 6\r\n       7 8 9 ]\u003c/pre\u003e\u003cp\u003eThen\u003c/p\u003e\u003cpre\u003e n = [ 1   2    6\r\n       4  20  120\r\n       7  56  504 ]\u003c/pre\u003e","function_template":"function y = MatMultiply(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =[ 1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [1 2 6;4 20 120; 7 56 504];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =reshape([1:10], 2,5);\r\ny_correct =   [ 1  3  15  105  945;\r\n                2  8  48  384  3840;];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =eye(5);\r\ny_correct =   [     1     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =ones(7);\r\ny_correct = ones(7);\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":397,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2014-02-12T21:23:36.000Z","updated_at":"2026-02-21T21:53:13.000Z","published_at":"2014-02-12T21:24:55.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ m = [ 1 2 3\\n       4 5 6\\n       7 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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[ n = [ 1   2    6\\n       4  20  120\\n       7  56  504 ]]]\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":2063,"title":"A matrix of extroverts","description":"Now that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well.  You will be given a matrix.  Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\r\n\r\nIf your input is magic(3)\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nYour output will be:\r\n\r\n  4.2500    4.7500\r\n  5.2500    5.7500\r\n\r\nThe top left term (4.25) is the average of [8 1 ; 3 5].  The bottom left term is the average of [3 5 ; 4 9], and so on.  You can assume that the size of each of these matrices will be at least 2x2.  Good luck!","description_html":"\u003cp\u003eNow that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well.  You will be given a matrix.  Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\u003c/p\u003e\u003cp\u003eIf your input is magic(3)\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eYour output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e4.2500    4.7500\r\n5.2500    5.7500\r\n\u003c/pre\u003e\u003cp\u003eThe top left term (4.25) is the average of [8 1 ; 3 5].  The bottom left term is the average of [3 5 ; 4 9], and so on.  You can assume that the size of each of these matrices will be at least 2x2.  Good luck!\u003c/p\u003e","function_template":"function y = extroverts(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(3);\r\ny = extroverts(x);\r\ny_c = [4.2500    4.7500 ; 5.2500    5.7500];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx = [1 2 3 ; 4 5 6];\r\ny = extroverts(x);\r\ny_c = [3 4];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx=[magic(4) -magic(4)];\r\ny = extroverts(x);\r\ny_c=[8.5  6.5 8.5 0   -8.5  -6.5 -8.5\r\n     8    8.5 9   1.5 -8    -8.5 -9\r\n     8.5 10.5 8.5 0   -8.5 -10.5 -8.5];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx = ones(20);\r\ny = extroverts(x);\r\ny_c = ones(19);\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":266,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-12-18T19:37:17.000Z","updated_at":"2026-02-21T21:48:09.000Z","published_at":"2013-12-18T19:37:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNow that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well. You will be given a matrix. Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 your input is magic(3)\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[     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\u003eYour output will be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[4.2500    4.7500\\n5.2500    5.7500]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe top left term (4.25) is the average of [8 1 ; 3 5]. The bottom left term is the average of [3 5 ; 4 9], and so on. You can assume that the size of each of these matrices will be at least 2x2. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1422,"title":"frame of the matrix","description":"Given the matrix M, return M without the external frame.","description_html":"\u003cp\u003eGiven the matrix M, return M without the external frame.\u003c/p\u003e","function_template":"function y = external_frame(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = eye(9);\r\ny = [1     0     0     0     0     0     0\r\n     0     1     0     0     0     0     0\r\n     0     0     1     0     0     0     0\r\n     0     0     0     1     0     0     0\r\n     0     0     0     0     1     0     0\r\n     0     0     0     0     0     1     0\r\n     0     0     0     0     0     0     1];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = magic(7);\r\ny = [47     7     9    18    27\r\n      6     8    17    26    35\r\n     14    16    25    34    36\r\n     15    24    33    42    44\r\n     23    32    41    43     3];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = ones(2,2);\r\ny = [];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = zeros(2,2);\r\ny = [];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = eye(3);\r\ny = 1;\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = ones(6,8);\r\ny = ones(4,6);\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = 1;\r\ny = [];\r\nassert(isequal(external_frame(x),y))","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":3919,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":925,"test_suite_updated_at":"2017-04-06T17:23:40.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-12T16:46:27.000Z","updated_at":"2026-03-24T18:28:46.000Z","published_at":"2013-04-12T16:46: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the matrix M, return M without the external frame.\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":42320,"title":"Write a function man that takes a row vector v and returns a matrix H as follows..","description":"Write a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example,\r\n if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].","description_html":"\u003cp\u003eWrite a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example,\r\n if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].\u003c/p\u003e","function_template":"function H = man(v)\r\n  % Read question Carefully!\r\nend","test_suite":"%%\r\nv = 0;\r\nH = [0 0 0];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv = [1 4];\r\nH =  [1 1 1;4 16 64];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv = [1 2 3];\r\nH = [ 1 1 1;2 4 8; 3 9 27];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv =[2 7 5 1 6 5 1 1 7 9 8 3 8 2 8 4 1 9];\r\nH =  [2 4 8;7 49 343;5 25 125;1 1 1;6 36 216;5 25 125;1 1 1;1 1 1;7 49 343;9 81 729;8 64 512;3 9 27;8 64 512;2 4 8;8 64 512;4 16 64;1     1     1;9    81   729];\r\nassert(isequal(man(v),H))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":44015,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":647,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2015-05-18T16:26:03.000Z","updated_at":"2026-02-28T12:00:39.000Z","published_at":"2015-05-18T16:26:27.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eWrite a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example, if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].\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":2701,"title":"Go to the head of the class!","description":"You're given a matrix and a single number.  If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position.  For example, your matrix is magic(3):\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nand the number is nine.  You want to change the matrix to  \r\n\r\n     9     2     4\r\n     1     6     8\r\n     5     7     3\r\n\r\nNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine.  If the number is not in the matrix, just return the original matrix.  Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front.  Good luck!","description_html":"\u003cp\u003eYou're given a matrix and a single number.  If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position.  For example, your matrix is magic(3):\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eand the number is nine.  You want to change the matrix to\u003c/p\u003e\u003cpre\u003e     9     2     4\r\n     1     6     8\r\n     5     7     3\u003c/pre\u003e\u003cp\u003eNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine.  If the number is not in the matrix, just return the original matrix.  Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front.  Good luck!\u003c/p\u003e","function_template":"function y = me_first(m,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nm = magic(3);\r\nn = 9;\r\ny_correct=[9     2     4;     1     6     8;     5     7     3];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm = magic(3);\r\nn = 15;\r\ny_correct=m;\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm=reshape(1:55,11,[]);\r\nn=42;\r\ny_correct=[42    53     9    20    31\r\n    43    54    10    21    32\r\n    44    55    11    22    33\r\n    34    45     1    12    23\r\n    35    46     2    13    24\r\n    36    47     3    14    25\r\n    37    48     4    15    26\r\n    38    49     5    16    27\r\n    39    50     6    17    28\r\n    40    51     7    18    29\r\n    41    52     8    19    30];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm=reshape(1:64,8,[])\r\nn=42;\r\nm(2)=42;\r\ny_correct=[42    10    18    26    34    42    50    58\r\n     3    11    19    27    35    43    51    59\r\n     4    12    20    28    36    44    52    60\r\n     5    13    21    29    37    45    53    61\r\n     6    14    22    30    38    46    54    62\r\n     7    15    23    31    39    47    55    63\r\n     8    16    24    32    40    48    56    64\r\n     1     9    17    25    33    41    49    57];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nx=randi(9)+3;\r\nm=ones(x);\r\nn=4;\r\nassert(isequal(me_first(m,n),m));\r\n\r\n%%\r\nx=randi(9)+3;\r\nm=ones(x);\r\nj=m;\r\nm(randi(numel(m)))=x\r\nn=x;\r\nj(1)=x;\r\nassert(isequal(me_first(m,n),j));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":148,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2014-12-02T15:15:59.000Z","updated_at":"2026-03-09T11:19:17.000Z","published_at":"2014-12-02T15:15:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou're given a matrix and a single number. If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position. For example, your matrix is magic(3):\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[     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\u003eand the number is nine. You want to change the matrix to\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[     9     2     4\\n     1     6     8\\n     5     7     3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine. If the number is not in the matrix, just return the original matrix. Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1421,"title":"subtract central cross","description":"Given an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.","description_html":"\u003cp\u003eGiven an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.\u003c/p\u003e","function_template":"function y = central_cross(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(7);\r\ny_correct = [30    39    48    10    19    28\r\n             38    47     7    18    27    29\r\n             46     6     8    26    35    37\r\n             13    15    24    42    44     4\r\n             21    23    32    43     3    12\r\n             22    31    40     2    11    20];\r\nassert(isequal(central_cross(x),y_correct))\r\n\r\n\r\n\r\n%%\r\nx = magic(3);\r\ny_correct = [8     6\r\n             4     2];\r\nassert(isequal(central_cross(x),y_correct))\r\n\r\n\r\n%%\r\nx = magic(1);\r\ny_correct = [];\r\nassert(isequal(central_cross(x),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":3919,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":740,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-12T16:32:41.000Z","updated_at":"2026-03-24T18:16:30.000Z","published_at":"2013-04-12T16:32:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.\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":2351,"title":"Replace Nonzero Numbers with 1","description":"Given the matrix x, return the matrix y with non zero elements replaced with 1.\r\n\r\nExample:\r\n\r\n Input  x =  [ 1 2 0 0 0\r\n               0 0 5 0 0 \r\n               2 7 0 0 0\r\n               0 6 9 3 3 ]\r\n\r\n Output y is [ 1 1 0 0 0\r\n               0 0 1 0 0 \r\n               1 1 0 0 0\r\n               0 1 1 1 1 ]","description_html":"\u003cp\u003eGiven the matrix x, return the matrix y with non zero elements replaced with 1.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  x =  [ 1 2 0 0 0\r\n               0 0 5 0 0 \r\n               2 7 0 0 0\r\n               0 6 9 3 3 ]\u003c/pre\u003e\u003cpre\u003e Output y is [ 1 1 0 0 0\r\n               0 0 1 0 0 \r\n               1 1 0 0 0\r\n               0 1 1 1 1 ]\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4 6 0\r\n     9 8 0 0 0];\r\ny_correct = [1 1 1 1 0\r\n             1 1 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [-1 2 NaN 6 \r\n      3 7 0 0 ];\r\ny_correct = [1 1 NaN 1 \r\n             1 1 0 0 ];\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = x;\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3*ones(5,7);\r\ny_correct = ones(5,7);\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = (1:5)'*(1:5);\r\ny_correct = ones(5,5);\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":6,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":446,"test_suite_updated_at":"2017-04-06T17:35:02.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-06-06T07:56:54.000Z","updated_at":"2026-02-28T11:58:09.000Z","published_at":"2014-06-06T07:56:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the matrix x, return the matrix y with non zero elements replaced with 1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  x =  [ 1 2 0 0 0\\n               0 0 5 0 0 \\n               2 7 0 0 0\\n               0 6 9 3 3 ]\\n\\n Output y is [ 1 1 0 0 0\\n               0 0 1 0 0 \\n               1 1 0 0 0\\n               0 1 1 1 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":2493,"title":"Must be in the front row...","description":"You are given a matrix followed by a single number.  Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix.  For example, if you start with the magic(4) matrix:\r\n\r\n     16     2     3    13\r\n      5    11    10     8\r\n      9     7     6    12\r\n      4    14    15     1\r\n\r\nand the number 6, your output should be:\r\n\r\n     6    12     9     7\r\n    15     1     4    14\r\n     3    13    16     2\r\n    10     8     5    11\r\n\r\nIf there is more than one instance of the number, use the one in the leftmost column.  If there is more than one in that column, use the one in the uppermost row.  If your input is a modified magic(4)\r\n\r\n    16     2     3    13\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n\r\nand you need to put 6 in the upper left corner, your output should be:\r\n\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n    16     2     3    13\r\n\r\nIf the input number isn't in the matrix, return the original matrix.  Good luck!","description_html":"\u003cp\u003eYou are given a matrix followed by a single number.  Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix.  For example, if you start with the magic(4) matrix:\u003c/p\u003e\u003cpre\u003e     16     2     3    13\r\n      5    11    10     8\r\n      9     7     6    12\r\n      4    14    15     1\u003c/pre\u003e\u003cp\u003eand the number 6, your output should be:\u003c/p\u003e\u003cpre\u003e     6    12     9     7\r\n    15     1     4    14\r\n     3    13    16     2\r\n    10     8     5    11\u003c/pre\u003e\u003cp\u003eIf there is more than one instance of the number, use the one in the leftmost column.  If there is more than one in that column, use the one in the uppermost row.  If your input is a modified magic(4)\u003c/p\u003e\u003cpre\u003e    16     2     3    13\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\u003c/pre\u003e\u003cp\u003eand you need to put 6 in the upper left corner, your output should be:\u003c/p\u003e\u003cpre\u003e     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n    16     2     3    13\u003c/pre\u003e\u003cp\u003eIf the input number isn't in the matrix, return the original matrix.  Good luck!\u003c/p\u003e","function_template":"function y = front_row(matrix,value)\r\n  y = x;\r\nend","test_suite":"%%\r\nmatrix=magic(4);\r\nvalue=6;\r\ny_correct=[6 12 9 7; 15 1 4 14; 3 13 16 2; 10 8 5 11];\r\nassert(isequal(front_row(matrix,value),y_correct))\r\n\r\n%%\r\nmatrix=magic(5);\r\nvalue=3;\r\nmatrix(3,2)=value;\r\ny_correct=[3 13 20 22 4; 12 19 21 3 10; 18 25 2 9 11; 24 1 8 15 17; 5 7 14 16 23];\r\nassert(isequal(front_row(matrix,value),y_correct))\r\n\r\n%%\r\nmatrix=magic(7);\r\nvalue=500;\r\nassert(isequal(front_row(matrix,value),matrix))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":"2014-08-08T17:54:32.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-08-08T17:46:02.000Z","updated_at":"2026-03-31T08:59:33.000Z","published_at":"2014-08-08T17:54:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are given a matrix followed by a single number. Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix. For example, if you start with the magic(4) 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[     16     2     3    13\\n      5    11    10     8\\n      9     7     6    12\\n      4    14    15     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\u003eand the number 6, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     6    12     9     7\\n    15     1     4    14\\n     3    13    16     2\\n    10     8     5    11]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there is more than one instance of the number, use the one in the leftmost column. If there is more than one in that column, use the one in the uppermost row. If your input is a modified magic(4)\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[    16     2     3    13\\n     6    11    10     8\\n     9     7     6    12\\n     6    14    15     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\u003eand you need to put 6 in the upper left corner, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     6    11    10     8\\n     9     7     6    12\\n     6    14    15     1\\n    16     2     3    13]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the input number isn't in the matrix, return the original matrix. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1853,"title":"Enlarge array","description":"Given an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q columns.\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  A = [1 2 3\r\n       4 5 6\r\n       7 8 9]\r\n  sz = [3 2]\r\n\r\nthen\r\n\r\n  B = [1 1 2 2 3 3\r\n       1 1 2 2 3 3\r\n       1 1 2 2 3 3\r\n       4 4 5 5 6 6\r\n       4 4 5 5 6 6\r\n       4 4 5 5 6 6\r\n       7 7 8 8 9 9\r\n       7 7 8 8 9 9\r\n       7 7 8 8 9 9]","description_html":"\u003cp\u003eGiven an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q columns.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     4 5 6\r\n     7 8 9]\r\nsz = [3 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eB = [1 1 2 2 3 3\r\n     1 1 2 2 3 3\r\n     1 1 2 2 3 3\r\n     4 4 5 5 6 6\r\n     4 4 5 5 6 6\r\n     4 4 5 5 6 6\r\n     7 7 8 8 9 9\r\n     7 7 8 8 9 9\r\n     7 7 8 8 9 9]\r\n\u003c/pre\u003e","function_template":"function B = enlarge(A,sz)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = randi(100);\r\nsz = [randi(100) 1];\r\nB_correct = repmat(A,sz);\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = randi(1000);\r\nsz = [1 randi(1000)];\r\nB_correct = repmat(A,sz);\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = eye(3);\r\nsz = [2 4];\r\nB_correct = [1 1 1 1 0 0 0 0 0 0 0 0;\r\n             1 1 1 1 0 0 0 0 0 0 0 0;\r\n             0 0 0 0 1 1 1 1 0 0 0 0;\r\n             0 0 0 0 1 1 1 1 0 0 0 0;\r\n             0 0 0 0 0 0 0 0 1 1 1 1;\r\n             0 0 0 0 0 0 0 0 1 1 1 1];\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = magic(4);\r\nsz = [3 3];\r\nB_correct = [16 16 16 2 2 2 3 3 3 13 13 13;\r\n             16 16 16 2 2 2 3 3 3 13 13 13;\r\n             16 16 16 2 2 2 3 3 3 13 13 13;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             4 4 4 14 14 14 15 15 15 1 1 1;\r\n             4 4 4 14 14 14 15 15 15 1 1 1;\r\n             4 4 4 14 14 14 15 15 15 1 1 1];\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = (-99:0)';\r\nsz = [1 100];\r\nB = enlarge(A,sz);\r\nassert(all(all(bsxfun(@minus,B,A)==0)))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":302,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-08-29T17:58:23.000Z","updated_at":"2026-02-21T20:59:42.000Z","published_at":"2013-08-29T17:58:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[A = [1 2 3\\n     4 5 6\\n     7 8 9]\\nsz = [3 2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[B = [1 1 2 2 3 3\\n     1 1 2 2 3 3\\n     1 1 2 2 3 3\\n     4 4 5 5 6 6\\n     4 4 5 5 6 6\\n     4 4 5 5 6 6\\n     7 7 8 8 9 9\\n     7 7 8 8 9 9\\n     7 7 8 8 9 9]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1898,"title":"Too Many Zeros, Dump Them!","description":"Sometimes when I create a matrix, I use this syntax:\r\n\r\n a = zeros(1000,1000);\r\n\r\nBut when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east of the matrix.\r\n\r\nFor example:\r\n  \r\n a1 = [1 2 0;\r\n       0 3 0;\r\n       0 0 0];\r\n\r\nI want to get a new matrix ,that is:\r\n\r\n b1 = [1 2;\r\n       0 3];\r\n\r\nAnother example:\r\n\r\n a2 = [1 2 0 4 0;\r\n       2 3 0 5 0;\r\n       3 4 0 6 0;\r\n       1 0 0 0 0];\r\n\r\n b2 = [1 2 0 4;\r\n       2 3 0 5;\r\n       3 4 0 6;\r\n       1 0 0 0];\r\n\r\nGood Luck!\r\n","description_html":"\u003cp\u003eSometimes when I create a matrix, I use this syntax:\u003c/p\u003e\u003cpre\u003e a = zeros(1000,1000);\u003c/pre\u003e\u003cp\u003eBut when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east of the matrix.\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cpre\u003e a1 = [1 2 0;\r\n       0 3 0;\r\n       0 0 0];\u003c/pre\u003e\u003cp\u003eI want to get a new matrix ,that is:\u003c/p\u003e\u003cpre\u003e b1 = [1 2;\r\n       0 3];\u003c/pre\u003e\u003cp\u003eAnother example:\u003c/p\u003e\u003cpre\u003e a2 = [1 2 0 4 0;\r\n       2 3 0 5 0;\r\n       3 4 0 6 0;\r\n       1 0 0 0 0];\u003c/pre\u003e\u003cpre\u003e b2 = [1 2 0 4;\r\n       2 3 0 5;\r\n       3 4 0 6;\r\n       1 0 0 0];\u003c/pre\u003e\u003cp\u003eGood Luck!\u003c/p\u003e","function_template":"function b = ZeroDumping(a)\r\nb=a;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = [];\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = [1 0];\r\ny_correct = 1;\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = [1 0 1 0;\r\n     0 0 1 0];\r\ny_correct = [1 0 1\r\n             0 0 1];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx=[1,0,  -3, 1i,0;\r\n   2,0.3,2i, 0, 0;\r\n   0,0,   0, inf, 0;\r\n   0,0,   0, 0, 1];\r\ny_correct =x;% x(4,5) is useful, I don't want to dump it.\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\teps];\r\ny_correct =x;\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[1\t1\t0\t0\t0\r\n    1\t0\t0\t0\t0\r\n    0\t0\t0\t3\t0\r\n    0\t0\t0\t0\t0\r\n    0\t0\t0\t0\t0];\r\ny_correct =[1\t1\t0\t0\r\n            1\t0\t0\t0\r\n            0\t0\t0\t3];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[1\t1\t0\t0\t0\r\n    1\t0\t0\t0\t0\r\n    0\t0\t0\t3\t0\r\n    0\t0\t0\t0\tinf\r\n    0\t0\t0\t0\t0];\r\ny_correct =[1\t1\t0\t0\t0\r\n\t    1\t0\t0\t0\t0\r\n\t    0\t0\t0\t3\t0\r\n\t    0\t0\t0\t0\tinf];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":7365,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":280,"test_suite_updated_at":"2013-09-27T16:23:12.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-09-27T11:48:40.000Z","updated_at":"2026-02-21T21:15:47.000Z","published_at":"2013-09-27T12:56:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSometimes when I create a matrix, I use this syntax:\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 = zeros(1000,1000);]]\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 when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east 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:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a1 = [1 2 0;\\n       0 3 0;\\n       0 0 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI want to get a new matrix ,that is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ b1 = [1 2;\\n       0 3];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a2 = [1 2 0 4 0;\\n       2 3 0 5 0;\\n       3 4 0 6 0;\\n       1 0 0 0 0];\\n\\n b2 = [1 2 0 4;\\n       2 3 0 5;\\n       3 4 0 6;\\n       1 0 0 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood Luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1429,"title":"Remove entire row and column in the matrix containing the input values","description":"Remove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by\r\nx =\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. \r\nOutput:[ 1 6;    9 2]\r\n\r\nremember the input value can be vector too !\r\n     ","description_html":"\u003cp\u003eRemove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by\r\nx =\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. \r\nOutput:[ 1 6;    9 2]\u003c/p\u003e\u003cp\u003eremember the input value can be vector too !\u003c/p\u003e","function_template":"function y = mat_remove(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(3); n=3;\r\ny_correct = [1 6; 9 2];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n\r\n%%\r\nx=eye(9); n=[1 0];\r\ny_correct = [];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n%%\r\nx=ones(8); n=1;\r\ny_correct = [];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n\r\n%%\r\nx=spiral(3); n=1;\r\ny_correct = [7 9; 5 3];\r\nassert(isequal(mat_remove(x,n),y_correct))","published":true,"deleted":false,"likes_count":10,"comments_count":2,"created_by":1023,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":557,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-16T01:20:27.000Z","updated_at":"2026-04-02T21:36:45.000Z","published_at":"2013-04-16T01:22:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRemove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by x =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     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\u003eand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. Output:[ 1 6; 9 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eremember the input value can be vector too !\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":42501,"title":"Toeplitize a matrix","description":"Similar to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix Problem 3094. Hankelize a matrix\u003e, now consider Toeplitization of a matrix.\r\n\r\nGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example, \r\n\r\nInput \r\n \r\n   A = [6     3     2     7\r\n\r\n        3     5     1     2\r\n\r\n        3     7    10     2]\r\n\r\nOutput:\r\n\r\n   B = [7     2     2     7 \r\n\r\n        5     7     2     2\r\n\r\n        3     5     7     2]\r\n","description_html":"\u003cp\u003eSimilar to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix\"\u003eProblem 3094. Hankelize a matrix\u003c/a\u003e, now consider Toeplitization of a matrix.\u003c/p\u003e\u003cp\u003eGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example,\u003c/p\u003e\u003cp\u003eInput\u003c/p\u003e\u003cpre\u003e   A = [6     3     2     7\u003c/pre\u003e\u003cpre\u003e        3     5     1     2\u003c/pre\u003e\u003cpre\u003e        3     7    10     2]\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre\u003e   B = [7     2     2     7 \u003c/pre\u003e\u003cpre\u003e        5     7     2     2\u003c/pre\u003e\u003cpre\u003e        3     5     7     2]\u003c/pre\u003e","function_template":"function B = toeplitize(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = 100;\r\nB = 100;\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [9,4;2,3;2,0];\r\nB = [6,4;1,6;2,1];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [7,10,9;5,1,0];\r\nB = [4,5,9;5,4,5];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [6 3 2 7;3 5 1 2;3 7 10 2];\r\nB = [7,2,2,7;5,7,2,2;3,5,7,2];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [3,-1,-10,1,4,2;8,4,0,4,2,0;2,0,-1,10,-3,6];\r\nB = [2,3,-3,3,2,2;4,2,3,-3,3,2;2,4,2,3,-3,3];\r\nassert(isequal(toeplitize(A),B))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":149,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2015-08-10T05:48:40.000Z","updated_at":"2026-03-29T07:17:50.000Z","published_at":"2015-08-10T05:49:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3094. Hankelize a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, now consider Toeplitization 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\u003eGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 = [6     3     2     7\\n\\n        3     5     1     2\\n\\n        3     7    10     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\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[   B = [7     2     2     7 \\n\\n        5     7     2     2\\n\\n        3     5     7     2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1972,"title":"Convert matrix to 3D array of triangular matrices","description":"Given a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\r\n\r\n* If the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\r\n* You may assume that P\u003c=100\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  x = 1  7 13\r\n      2  8 14\r\n      3  9 15\r\n      4 10 16\r\n      5 11 17\r\n      6 12 18\r\n\r\nthen\r\n\r\n  y(:,:,1) =  1  2  4\r\n              0  3  5\r\n              0  0  6\r\n\r\n  y(:,:,2) =  7  8 10\r\n              0  9 11\r\n              0  0 12\r\n\r\n  y(:,:,3) = 13 14 16\r\n              0 15 17\r\n              0  0 18\r\n\r\n_NOTE:_ If you are wondering why this seems like a strange task, it is inspired by a genotype-\u003ephenotype mapping I am doing in a genetic algorithm.","description_html":"\u003cp\u003eGiven a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\u003c/li\u003e\u003cli\u003eYou may assume that P\u0026lt;=100\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 1  7 13\r\n    2  8 14\r\n    3  9 15\r\n    4 10 16\r\n    5 11 17\r\n    6 12 18\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,1) =  1  2  4\r\n            0  3  5\r\n            0  0  6\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,2) =  7  8 10\r\n            0  9 11\r\n            0  0 12\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,3) = 13 14 16\r\n            0 15 17\r\n            0  0 18\r\n\u003c/pre\u003e\u003cp\u003e\u003ci\u003eNOTE:\u003c/i\u003e If you are wondering why this seems like a strange task, it is inspired by a genotype-\u0026gt;phenotype mapping I am doing in a genetic algorithm.\u003c/p\u003e","function_template":"function y = mat2triu3(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1:100;\r\ny_correct = shiftdim(x,-1);\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:15,3,[]);\r\ny_correct(:,:,1) = [1 2;0 3];\r\ny_correct(:,:,2) = [4 5;0 6];\r\ny_correct(:,:,3) = [7 8;0 9];\r\ny_correct(:,:,4) = [10 11;0 12];\r\ny_correct(:,:,5) = [13 14;0 15];\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:18,3,[])';\r\ny_correct(:,:,1) = [1 4 10; 0 7 13; 0 0 16];\r\ny_correct(:,:,2) = [2 5 11; 0 8 14; 0 0 17];\r\ny_correct(:,:,3) = [3 6 12; 0 9 15; 0 0 18];\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = randi(50,sum(1:100),22);\r\ny = mat2triu3(x);\r\nmask = (y~=0);\r\nxb = reshape(y(mask),[],size(y,3));\r\nassert(isequal(size(y),[100 100 22]))\r\nassert(isequal(x,xb))\r\n\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":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-11-07T22:49:47.000Z","updated_at":"2026-03-31T09:10:36.000Z","published_at":"2013-11-07T22:58:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\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\u003eIf the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\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\u003eYou may assume that P\u0026lt;=100\u003c/w:t\u003e\u003c/w:r\u003e\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 = 1  7 13\\n    2  8 14\\n    3  9 15\\n    4 10 16\\n    5 11 17\\n    6 12 18]]\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(:,:,1) =  1  2  4\\n            0  3  5\\n            0  0  6\\n\\ny(:,:,2) =  7  8 10\\n            0  9 11\\n            0  0 12\\n\\ny(:,:,3) = 13 14 16\\n            0 15 17\\n            0  0 18]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNOTE:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e If you are wondering why this seems like a strange task, it is inspired by a genotype-\u0026gt;phenotype mapping I am doing in a genetic algorithm.\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":2442,"title":"Magnet and Iron","description":"(Inspired from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/112 Problem 112: Remove the air bubbles\u003e)\r\n\r\nIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\r\n\r\nExample:\r\n\r\n Input =\r\n  \r\n       1    26\r\n       3    26\r\n      26    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\r\n  \r\n Output =\r\n      26    26\r\n       1    26\r\n       3    26\r\n       0     0\r\n     -12   NaN\r\n      26    26","description_html":"\u003cp\u003e(Inspired from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/112\"\u003eProblem 112: Remove the air bubbles\u003c/a\u003e)\u003c/p\u003e\u003cp\u003eIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input =\u003c/pre\u003e\u003cpre\u003e       1    26\r\n       3    26\r\n      26    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\u003c/pre\u003e\u003cpre\u003e Output =\r\n      26    26\r\n       1    26\r\n       3    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\u003c/pre\u003e","function_template":"function y = strongMagnet(x)\r\n\r\nend","test_suite":"%%\r\nx = [1 1;1 0;1 26; 26 0; 26 26 ;0 1;1 1]\r\ny_correct =[1    26\r\n     1     1\r\n     1     0\r\n    26     0\r\n     0     1\r\n     1     1\r\n    26    26];\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n\r\n%%\r\nx = 26*ones(26,26);\r\ny_correct = x;\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n\r\n%%\r\nx = zeros(26,26);\r\ny_correct = x;\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n%%\r\nx = [1 26; 3 26; 26 26; 0 0; -12 nan; 26 26]\r\ny_correct = [26    26\r\n     1    26\r\n     3    26\r\n     0     0\r\n   -12   NaN\r\n    26    26];\r\nassert(isequalwithequalnans(strongMagnet(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":"2014-07-16T17:56:54.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-07-16T17:54:30.000Z","updated_at":"2026-03-31T08:57:16.000Z","published_at":"2014-07-16T17:54:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(Inspired from\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/112\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 112: Remove the air bubbles\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 =\\n\\n       1    26\\n       3    26\\n      26    26\\n       0     0\\n     -12   NaN\\n      26    26\\n\\n Output =\\n      26    26\\n       1    26\\n       3    26\\n       0     0\\n     -12   NaN\\n      26    26]]\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":3094,"title":"Hankelize a matrix","description":"Similar to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix Problem 42501. Toeplitize a matrix\u003e, let's consider Hankelization of a matrix.\r\n\r\nGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example, \r\n\r\nInput \r\n \r\n   A = [3     7    10     2\r\n\r\n        3     5     1     2\r\n\r\n        6     3     2     7]\r\n\r\nOutput:\r\n\r\n   B = [3     5     7     2 \r\n\r\n        5     7     2     2\r\n\r\n        7     2     2     7]\r\n\r\n\r\n","description_html":"\u003cp\u003eSimilar to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix\"\u003eProblem 42501. Toeplitize a matrix\u003c/a\u003e, let's consider Hankelization of a matrix.\u003c/p\u003e\u003cp\u003eGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example,\u003c/p\u003e\u003cp\u003eInput\u003c/p\u003e\u003cpre\u003e   A = [3     7    10     2\u003c/pre\u003e\u003cpre\u003e        3     5     1     2\u003c/pre\u003e\u003cpre\u003e        6     3     2     7]\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre\u003e   B = [3     5     7     2 \u003c/pre\u003e\u003cpre\u003e        5     7     2     2\u003c/pre\u003e\u003cpre\u003e        7     2     2     7]\u003c/pre\u003e","function_template":"function B = hankelize(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = 100;\r\nB = 100;\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [2,0\r\n     2,3\r\n     9,4];\r\nB = [2,1\r\n     1,6\r\n     6,4];\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [5  1   0\r\n     7  10  9];\r\nB = [5   4   5\r\n     4   5   9];\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [3 7 10 2\r\n     3 5  1 2\r\n     6 3  2 7];\r\nB = [3 5 7 2\r\n     5 7 2 2\r\n     7 2 2 7];\r\nassert(isequal(hankelize(A),B));\r\n\r\n\r\n%%\r\nA = [2  0  -1 10 -3  6\r\n     8  4   0  4  2  0\r\n     3 -1 -10  1  4  2];\r\nB = [2 4  2  3 -3 3\r\n     4 2  3 -3  3 2\r\n     2 3 -3  3  2 2];\r\nassert(isequal(hankelize(A),B));","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":158,"test_suite_updated_at":"2015-10-31T18:03:02.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2015-03-19T14:42:36.000Z","updated_at":"2026-02-27T20:57:57.000Z","published_at":"2015-08-09T21:41:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42501. Toeplitize a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, let's consider Hankelization 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\u003eGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 = [3     7    10     2\\n\\n        3     5     1     2\\n\\n        6     3     2     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\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[   B = [3     5     7     2 \\n\\n        5     7     2     2\\n\\n        7     2     2     7]]]\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":3075,"title":"Matrix of Multiplication Facts","description":"This is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\r\nThe matrix we were given is:\r\n 21   6\r\n 35  10\r\nThe correct answer is:\r\n 21  3   6\r\n  7  0   2\r\n 35  5  10\r\nThe two numbers touching the 21 are 7 and 3, and 7x3=21.\r\nThe two numbers touching the 35 are 7 and 5, and 7x5=35.\r\nThe two numbers touching the 6 are 2 and 3, and 2x3=6.\r\nThe two numbers touching the 10 are 2 and 5, and 2x5=10.\r\nThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!","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: 441.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 220.95px; transform-origin: 407px 220.95px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\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: 88.5px 8px; transform-origin: 88.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe matrix we were given is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 21   6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 35  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe correct answer is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 21  3   6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  7  0   2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 35  5  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cul style=\"block-size: 81.7333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 40.8667px; transform-origin: 391px 40.8667px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 21 are 7 and 3, and 7x3=21.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 35 are 7 and 5, and 7x5=35.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 179px 8px; transform-origin: 179px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 6 are 2 and 3, and 2x3=6.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 10 are 2 and 5, and 2x5=10.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 372px 8px; transform-origin: 372px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = factor_square(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [21 6 ; 35 10];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [6 8 ; 15 20];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx=[35 42 ; 15 18];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [432 288 ; 288 192];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [21 63 ; 15 45];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [110 132 ; 130 156];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\np=primes(1000);\r\nj=randperm(numel(p));\r\np=p(j(1:4));\r\nx=[p(1)*p(2) p(1)*p(3) ; p(2)*p(4) p(3)*p(4)]\r\ny=factor_square(x)\r\n\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\np=primes(100000);\r\np(p\u003c50000)=[];\r\nj=randperm(numel(p));\r\np=p(j(1:4))\r\nx=[p(1)*p(2) p(1)*p(3) ; p(2)*p(4) p(3)*p(4)]\r\ny=factor_square(x)\r\n\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\n","published":true,"deleted":false,"likes_count":13,"comments_count":6,"created_by":1615,"edited_by":223089,"edited_at":"2023-03-01T15:42:21.000Z","deleted_by":null,"deleted_at":null,"solvers_count":148,"test_suite_updated_at":"2023-03-01T15:42:21.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2015-03-10T13:49:14.000Z","updated_at":"2026-03-29T08:01:57.000Z","published_at":"2015-03-10T13:49:14.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\u003eThis is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe matrix we were given is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 21   6\\n 35  10]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 21  3   6\\n  7  0   2\\n 35  5  10]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 21 are 7 and 3, and 7x3=21.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 35 are 7 and 5, and 7x5=35.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 6 are 2 and 3, and 2x3=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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 10 are 2 and 5, and 2x5=10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!\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":1167,"title":"matrix zigzag","description":"Unfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\r\n\r\n [ 1 2 3 ;\r\n   4 5 6 ;\r\n   7 8 9 ] \r\n\r\nthe resulting 1-D array should be \r\n\r\n [ 1 2 4 7 5 3 6 8 9 ]","description_html":"\u003cp\u003eUnfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\u003c/p\u003e\u003cpre\u003e [ 1 2 3 ;\r\n   4 5 6 ;\r\n   7 8 9 ] \u003c/pre\u003e\u003cp\u003ethe resulting 1-D array should be\u003c/p\u003e\u003cpre\u003e [ 1 2 4 7 5 3 6 8 9 ]\u003c/pre\u003e","function_template":"function y = zigzag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = [1 2 3 4];\r\nassert(isequal(zigzag(x),y_correct))\r\n\r\n%%\r\nx = [ 1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [ 1 2 4 7 5 3 6 8 9];\r\nassert(isequal(zigzag(x),y_correct))\r\n\r\n%%\r\nx = magic(4);\r\ny_correct = [16 2 5 9 11 3 13 10 7 4 14 6 8 12 15 1];\r\nassert(isequal(zigzag(x),y_correct))","published":true,"deleted":false,"likes_count":12,"comments_count":0,"created_by":9535,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":347,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-01-04T03:24:14.000Z","updated_at":"2026-03-27T17:34:35.000Z","published_at":"2013-01-04T03:24:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUnfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [ 1 2 3 ;\\n   4 5 6 ;\\n   7 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe resulting 1-D array should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [ 1 2 4 7 5 3 6 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1286,"title":"MatCAT - Reconstruct X from Its X-rays","description":"Consider a matrix x\r\n\r\n x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\r\n\r\nIf we sum x along the rows we get\r\n\r\n row_sums = [3 5 11]\r\n\r\nSumming along the columns gives \r\n\r\n col_sums = [4 7 8]\r\n\r\nMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003chttp://en.wikipedia.org/wiki/X-ray_computed_tomography CAT scan\u003e. Can you put all the bones in the right place?\r\n\r\nAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\r\n\r\nBonus question: Under what circumstances does the answer become unique? Discuss.","description_html":"\u003cp\u003eConsider a matrix x\u003c/p\u003e\u003cpre\u003e x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\u003c/pre\u003e\u003cp\u003eIf we sum x along the rows we get\u003c/p\u003e\u003cpre\u003e row_sums = [3 5 11]\u003c/pre\u003e\u003cp\u003eSumming along the columns gives\u003c/p\u003e\u003cpre\u003e col_sums = [4 7 8]\u003c/pre\u003e\u003cp\u003eMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003ca href = \"http://en.wikipedia.org/wiki/X-ray_computed_tomography\"\u003eCAT scan\u003c/a\u003e. Can you put all the bones in the right place?\u003c/p\u003e\u003cp\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/p\u003e\u003cp\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\u003c/p\u003e","function_template":"function x = matcat(row_sums,col_sums)\r\n  x = 0;\r\nend","test_suite":"%%\r\nrow_sums = [3 5 11];\r\ncol_sums = [4 7 8];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [2 2 2 2 2 6];\r\ncol_sums = [2 3 3 3 3 2];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [65 65 65 65 65];\r\ncol_sums = [65 65 65 65 65];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [22 34 33];\r\ncol_sums = [15 23 18 21 12];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = 55;\r\ncol_sums = [1 2 3 4 5 6 7 8 9 10];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":147,"test_suite_updated_at":"2013-02-21T17:46:45.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-02-21T17:25:12.000Z","updated_at":"2026-04-02T21:49:21.000Z","published_at":"2013-02-21T17:46:45.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\u003eConsider a matrix x\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [ 1 2 0\\n       0 5 0 \\n       3 0 8 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we sum x along the rows we 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[ row_sums = [3 5 11]]]\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\u003eSumming along the columns gives\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[ col_sums = [4 7 8]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMetaphorically, we might call these sums \\\"x-rays\\\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/X-ray_computed_tomography\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCAT scan\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Can you put all the bones in the right place?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\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":1321,"title":"Given a matrix, swap the 2nd \u0026 3rd columns","description":"If\r\n\r\n a = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4];\r\n\r\nthen the result is\r\n\r\n ans =\r\n\r\n     1     3     2     4\r\n     1     3     2     4\r\n     1     3     2     4\r\n     1     3     2     4\r\n\r\nPerform a simple swap of the two middle columns.","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: 266.467px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 133.233px; transform-origin: 407px 133.233px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 3.5px 8px; transform-origin: 3.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eIf\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003ea = [1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 52px 8.5px; transform-origin: 52px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4;\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e     1 2 3 4];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 52.5px 8px; transform-origin: 52.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003ethen the result is\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 81.7333px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 40.8667px; transform-origin: 404px 40.8667px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003eans = [1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 56px 8.5px; transform-origin: 56px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 64px 8.5px; transform-origin: 64px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e       1 3 2 4];\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 95px 8px; transform-origin: 95px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eby swapping columns 2 and 3.\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = swapmid(x)\r\n  y = 'swap';\r\nend","test_suite":"%%\r\nx =         [1 2 3 4;1 2 3 4;1 2 3 4;1 2 3 4];\r\ny_correct = [1 3 2 4;1 3 2 4;1 3 2 4;1 3 2 4];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [1 2 3 4;5 6 7 8;1 2 3 4;5 6 7 8];\r\ny_correct = [1 3 2 4;5 7 6 8;1 3 2 4;5 7 6 8];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         ones(5,3);\r\ny_correct = x;\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         eye(5);\r\ny_correct = [1 0 0 0 0; 0 0 1 0 0; 0 1 0 0 0; 0 0 0 1 0; 0 0 0 0 1];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [1:7; 2:8; 3:9];\r\ny_correct = [1 3 2 4:7; 2 4 3 5:8; 3 5 4 6:9];\r\nassert(isequal(swapmid(x),y_correct))\r\n\r\n%%\r\nx =         [ones(10,1),zeros(10,1),5*ones(10,1)];\r\ny_correct = [ones(10,1),5*ones(10,1),zeros(10,1)];\r\nassert(isequal(swapmid(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":11,"comments_count":7,"created_by":6975,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":1265,"test_suite_updated_at":"2017-04-06T17:19:25.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-03-07T05:26:33.000Z","updated_at":"2026-04-02T09:37:04.000Z","published_at":"2013-03-07T05:26:33.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[a = [1 2 3 4;\\n     1 2 3 4;\\n     1 2 3 4;\\n     1 2 3 4];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen the result is\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ans = [1 3 2 4\\n       1 3 2 4\\n       1 3 2 4\\n       1 3 2 4];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eby swapping columns 2 and 3.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\",\"relationship\":null}],\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"target\":\"/matlab/document.xml\",\"relationshipId\":\"rId1\"}]}"},{"id":2178,"title":"Matrix multiplication across rows","description":"Given matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\r\n\r\nExample\r\n \r\n m = [ 1 2 3\r\n       4 5 6\r\n       7 8 9 ]\r\n\r\nThen\r\n\r\n n = [ 1   2    6\r\n       4  20  120\r\n       7  56  504 ]\r\n\r\n","description_html":"\u003cp\u003eGiven matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\u003c/p\u003e\u003cp\u003eExample\u003c/p\u003e\u003cpre\u003e m = [ 1 2 3\r\n       4 5 6\r\n       7 8 9 ]\u003c/pre\u003e\u003cp\u003eThen\u003c/p\u003e\u003cpre\u003e n = [ 1   2    6\r\n       4  20  120\r\n       7  56  504 ]\u003c/pre\u003e","function_template":"function y = MatMultiply(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx =[ 1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [1 2 6;4 20 120; 7 56 504];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =reshape([1:10], 2,5);\r\ny_correct =   [ 1  3  15  105  945;\r\n                2  8  48  384  3840;];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =eye(5);\r\ny_correct =   [     1     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;\r\n                    0     0     0     0     0;];\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n%%\r\nx =ones(7);\r\ny_correct = ones(7);\r\nassert(isequal(MatMultiply(x),y_correct))\r\n\r\n\r\n","published":true,"deleted":false,"likes_count":4,"comments_count":0,"created_by":16381,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":397,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2014-02-12T21:23:36.000Z","updated_at":"2026-02-21T21:53:13.000Z","published_at":"2014-02-12T21:24:55.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven matrix m, return matrix n such that, rows of n are result of multiplication of the rows of the input matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ m = [ 1 2 3\\n       4 5 6\\n       7 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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[ n = [ 1   2    6\\n       4  20  120\\n       7  56  504 ]]]\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":2063,"title":"A matrix of extroverts","description":"Now that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well.  You will be given a matrix.  Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\r\n\r\nIf your input is magic(3)\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nYour output will be:\r\n\r\n  4.2500    4.7500\r\n  5.2500    5.7500\r\n\r\nThe top left term (4.25) is the average of [8 1 ; 3 5].  The bottom left term is the average of [3 5 ; 4 9], and so on.  You can assume that the size of each of these matrices will be at least 2x2.  Good luck!","description_html":"\u003cp\u003eNow that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well.  You will be given a matrix.  Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\u003c/p\u003e\u003cp\u003eIf your input is magic(3)\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eYour output will be:\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003e4.2500    4.7500\r\n5.2500    5.7500\r\n\u003c/pre\u003e\u003cp\u003eThe top left term (4.25) is the average of [8 1 ; 3 5].  The bottom left term is the average of [3 5 ; 4 9], and so on.  You can assume that the size of each of these matrices will be at least 2x2.  Good luck!\u003c/p\u003e","function_template":"function y = extroverts(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(3);\r\ny = extroverts(x);\r\ny_c = [4.2500    4.7500 ; 5.2500    5.7500];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx = [1 2 3 ; 4 5 6];\r\ny = extroverts(x);\r\ny_c = [3 4];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx=[magic(4) -magic(4)];\r\ny = extroverts(x);\r\ny_c=[8.5  6.5 8.5 0   -8.5  -6.5 -8.5\r\n     8    8.5 9   1.5 -8    -8.5 -9\r\n     8.5 10.5 8.5 0   -8.5 -10.5 -8.5];\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);\r\n%%\r\nx = ones(20);\r\ny = extroverts(x);\r\ny_c = ones(19);\r\nassert(max(max(abs(y-y_c)))\u003c1e-9);","published":true,"deleted":false,"likes_count":3,"comments_count":0,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":266,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-12-18T19:37:17.000Z","updated_at":"2026-02-21T21:48:09.000Z","published_at":"2013-12-18T19:37:17.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNow that the introverts have had their script, the extroverts spoke up (naturally!) and demanded one as well. You will be given a matrix. Write a MATLAB script to output a new matrix consisting of the average of all four terms that are next to each other.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 your input is magic(3)\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[     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\u003eYour output will be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[4.2500    4.7500\\n5.2500    5.7500]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe top left term (4.25) is the average of [8 1 ; 3 5]. The bottom left term is the average of [3 5 ; 4 9], and so on. You can assume that the size of each of these matrices will be at least 2x2. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1422,"title":"frame of the matrix","description":"Given the matrix M, return M without the external frame.","description_html":"\u003cp\u003eGiven the matrix M, return M without the external frame.\u003c/p\u003e","function_template":"function y = external_frame(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = eye(9);\r\ny = [1     0     0     0     0     0     0\r\n     0     1     0     0     0     0     0\r\n     0     0     1     0     0     0     0\r\n     0     0     0     1     0     0     0\r\n     0     0     0     0     1     0     0\r\n     0     0     0     0     0     1     0\r\n     0     0     0     0     0     0     1];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = magic(7);\r\ny = [47     7     9    18    27\r\n      6     8    17    26    35\r\n     14    16    25    34    36\r\n     15    24    33    42    44\r\n     23    32    41    43     3];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = ones(2,2);\r\ny = [];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = zeros(2,2);\r\ny = [];\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = eye(3);\r\ny = 1;\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = ones(6,8);\r\ny = ones(4,6);\r\nassert(isequal(external_frame(x),y))\r\n\r\n%%\r\nx = 1;\r\ny = [];\r\nassert(isequal(external_frame(x),y))","published":true,"deleted":false,"likes_count":8,"comments_count":1,"created_by":3919,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":925,"test_suite_updated_at":"2017-04-06T17:23:40.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-12T16:46:27.000Z","updated_at":"2026-03-24T18:28:46.000Z","published_at":"2013-04-12T16:46: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\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the matrix M, return M without the external frame.\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":42320,"title":"Write a function man that takes a row vector v and returns a matrix H as follows..","description":"Write a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example,\r\n if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].","description_html":"\u003cp\u003eWrite a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example,\r\n if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].\u003c/p\u003e","function_template":"function H = man(v)\r\n  % Read question Carefully!\r\nend","test_suite":"%%\r\nv = 0;\r\nH = [0 0 0];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv = [1 4];\r\nH =  [1 1 1;4 16 64];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv = [1 2 3];\r\nH = [ 1 1 1;2 4 8; 3 9 27];\r\nassert(isequal(man(v),H))\r\n\r\n%%\r\nv =[2 7 5 1 6 5 1 1 7 9 8 3 8 2 8 4 1 9];\r\nH =  [2 4 8;7 49 343;5 25 125;1 1 1;6 36 216;5 25 125;1 1 1;1 1 1;7 49 343;9 81 729;8 64 512;3 9 27;8 64 512;2 4 8;8 64 512;4 16 64;1     1     1;9    81   729];\r\nassert(isequal(man(v),H))","published":true,"deleted":false,"likes_count":1,"comments_count":0,"created_by":44015,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":647,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2015-05-18T16:26:03.000Z","updated_at":"2026-02-28T12:00:39.000Z","published_at":"2015-05-18T16:26:27.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"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\u003eWrite a function called man that takes a row vector v as an input and returns a matrix H whose first column consist of the elements of v, whose second column consists of the squares of the elements of v, and whose third column consists of the cubes of the elements v. For example, if A = man(1:3) , then A will be [ 1 1 1; 2 4 8; 3 9 27 ].\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":2701,"title":"Go to the head of the class!","description":"You're given a matrix and a single number.  If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position.  For example, your matrix is magic(3):\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nand the number is nine.  You want to change the matrix to  \r\n\r\n     9     2     4\r\n     1     6     8\r\n     5     7     3\r\n\r\nNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine.  If the number is not in the matrix, just return the original matrix.  Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front.  Good luck!","description_html":"\u003cp\u003eYou're given a matrix and a single number.  If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position.  For example, your matrix is magic(3):\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eand the number is nine.  You want to change the matrix to\u003c/p\u003e\u003cpre\u003e     9     2     4\r\n     1     6     8\r\n     5     7     3\u003c/pre\u003e\u003cp\u003eNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine.  If the number is not in the matrix, just return the original matrix.  Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front.  Good luck!\u003c/p\u003e","function_template":"function y = me_first(m,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nm = magic(3);\r\nn = 9;\r\ny_correct=[9     2     4;     1     6     8;     5     7     3];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm = magic(3);\r\nn = 15;\r\ny_correct=m;\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm=reshape(1:55,11,[]);\r\nn=42;\r\ny_correct=[42    53     9    20    31\r\n    43    54    10    21    32\r\n    44    55    11    22    33\r\n    34    45     1    12    23\r\n    35    46     2    13    24\r\n    36    47     3    14    25\r\n    37    48     4    15    26\r\n    38    49     5    16    27\r\n    39    50     6    17    28\r\n    40    51     7    18    29\r\n    41    52     8    19    30];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nm=reshape(1:64,8,[])\r\nn=42;\r\nm(2)=42;\r\ny_correct=[42    10    18    26    34    42    50    58\r\n     3    11    19    27    35    43    51    59\r\n     4    12    20    28    36    44    52    60\r\n     5    13    21    29    37    45    53    61\r\n     6    14    22    30    38    46    54    62\r\n     7    15    23    31    39    47    55    63\r\n     8    16    24    32    40    48    56    64\r\n     1     9    17    25    33    41    49    57];\r\nassert(isequal(me_first(m,n),y_correct));\r\n\r\n%%\r\nx=randi(9)+3;\r\nm=ones(x);\r\nn=4;\r\nassert(isequal(me_first(m,n),m));\r\n\r\n%%\r\nx=randi(9)+3;\r\nm=ones(x);\r\nj=m;\r\nm(randi(numel(m)))=x\r\nn=x;\r\nj(1)=x;\r\nassert(isequal(me_first(m,n),j));\r\n","published":true,"deleted":false,"likes_count":2,"comments_count":2,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":148,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2014-12-02T15:15:59.000Z","updated_at":"2026-03-09T11:19:17.000Z","published_at":"2014-12-02T15:15:59.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou're given a matrix and a single number. If that number is in the matrix, reorder the matrix so that number is in the first row and first column of the matrix, and keep all of the other numbers in the same relative position. For example, your matrix is magic(3):\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[     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\u003eand the number is nine. You want to change the matrix to\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[     9     2     4\\n     1     6     8\\n     5     7     3]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eNine is now in the (1,1) position, and all of the other numbers are in the same relative position to nine. If the number is not in the matrix, just return the original matrix. Likewise, if the number appears more than once, make sure the first instance of the number is the one that is moved to the front. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1421,"title":"subtract central cross","description":"Given an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.","description_html":"\u003cp\u003eGiven an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.\u003c/p\u003e","function_template":"function y = central_cross(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(7);\r\ny_correct = [30    39    48    10    19    28\r\n             38    47     7    18    27    29\r\n             46     6     8    26    35    37\r\n             13    15    24    42    44     4\r\n             21    23    32    43     3    12\r\n             22    31    40     2    11    20];\r\nassert(isequal(central_cross(x),y_correct))\r\n\r\n\r\n\r\n%%\r\nx = magic(3);\r\ny_correct = [8     6\r\n             4     2];\r\nassert(isequal(central_cross(x),y_correct))\r\n\r\n\r\n%%\r\nx = magic(1);\r\ny_correct = [];\r\nassert(isequal(central_cross(x),y_correct))","published":true,"deleted":false,"likes_count":7,"comments_count":0,"created_by":3919,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":740,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-12T16:32:41.000Z","updated_at":"2026-03-24T18:16:30.000Z","published_at":"2013-04-12T16:32:41.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an n-by-n square matrix, where n is an odd number, return the matrix without the central row and the central column.\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":2351,"title":"Replace Nonzero Numbers with 1","description":"Given the matrix x, return the matrix y with non zero elements replaced with 1.\r\n\r\nExample:\r\n\r\n Input  x =  [ 1 2 0 0 0\r\n               0 0 5 0 0 \r\n               2 7 0 0 0\r\n               0 6 9 3 3 ]\r\n\r\n Output y is [ 1 1 0 0 0\r\n               0 0 1 0 0 \r\n               1 1 0 0 0\r\n               0 1 1 1 1 ]","description_html":"\u003cp\u003eGiven the matrix x, return the matrix y with non zero elements replaced with 1.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input  x =  [ 1 2 0 0 0\r\n               0 0 5 0 0 \r\n               2 7 0 0 0\r\n               0 6 9 3 3 ]\u003c/pre\u003e\u003cpre\u003e Output y is [ 1 1 0 0 0\r\n               0 0 1 0 0 \r\n               1 1 0 0 0\r\n               0 1 1 1 1 ]\u003c/pre\u003e","function_template":"function y = your_fcn_name(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2 4 6 0\r\n     9 8 0 0 0];\r\ny_correct = [1 1 1 1 0\r\n             1 1 0 0 0];\r\nassert(isequal(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = [-1 2 NaN 6 \r\n      3 7 0 0 ];\r\ny_correct = [1 1 NaN 1 \r\n             1 1 0 0 ];\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = eye(4);\r\ny_correct = x;\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = 3*ones(5,7);\r\ny_correct = ones(5,7);\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n\r\n%%\r\nx = (1:5)'*(1:5);\r\ny_correct = ones(5,5);\r\nassert(isequaln(your_fcn_name(x),y_correct))\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":6,"created_by":25856,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":446,"test_suite_updated_at":"2017-04-06T17:35:02.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-06-06T07:56:54.000Z","updated_at":"2026-02-28T11:58:09.000Z","published_at":"2014-06-06T07:56:58.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven the matrix x, return the matrix y with non zero elements replaced with 1.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eExample:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ Input  x =  [ 1 2 0 0 0\\n               0 0 5 0 0 \\n               2 7 0 0 0\\n               0 6 9 3 3 ]\\n\\n Output y is [ 1 1 0 0 0\\n               0 0 1 0 0 \\n               1 1 0 0 0\\n               0 1 1 1 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":2493,"title":"Must be in the front row...","description":"You are given a matrix followed by a single number.  Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix.  For example, if you start with the magic(4) matrix:\r\n\r\n     16     2     3    13\r\n      5    11    10     8\r\n      9     7     6    12\r\n      4    14    15     1\r\n\r\nand the number 6, your output should be:\r\n\r\n     6    12     9     7\r\n    15     1     4    14\r\n     3    13    16     2\r\n    10     8     5    11\r\n\r\nIf there is more than one instance of the number, use the one in the leftmost column.  If there is more than one in that column, use the one in the uppermost row.  If your input is a modified magic(4)\r\n\r\n    16     2     3    13\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n\r\nand you need to put 6 in the upper left corner, your output should be:\r\n\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n    16     2     3    13\r\n\r\nIf the input number isn't in the matrix, return the original matrix.  Good luck!","description_html":"\u003cp\u003eYou are given a matrix followed by a single number.  Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix.  For example, if you start with the magic(4) matrix:\u003c/p\u003e\u003cpre\u003e     16     2     3    13\r\n      5    11    10     8\r\n      9     7     6    12\r\n      4    14    15     1\u003c/pre\u003e\u003cp\u003eand the number 6, your output should be:\u003c/p\u003e\u003cpre\u003e     6    12     9     7\r\n    15     1     4    14\r\n     3    13    16     2\r\n    10     8     5    11\u003c/pre\u003e\u003cp\u003eIf there is more than one instance of the number, use the one in the leftmost column.  If there is more than one in that column, use the one in the uppermost row.  If your input is a modified magic(4)\u003c/p\u003e\u003cpre\u003e    16     2     3    13\r\n     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\u003c/pre\u003e\u003cp\u003eand you need to put 6 in the upper left corner, your output should be:\u003c/p\u003e\u003cpre\u003e     6    11    10     8\r\n     9     7     6    12\r\n     6    14    15     1\r\n    16     2     3    13\u003c/pre\u003e\u003cp\u003eIf the input number isn't in the matrix, return the original matrix.  Good luck!\u003c/p\u003e","function_template":"function y = front_row(matrix,value)\r\n  y = x;\r\nend","test_suite":"%%\r\nmatrix=magic(4);\r\nvalue=6;\r\ny_correct=[6 12 9 7; 15 1 4 14; 3 13 16 2; 10 8 5 11];\r\nassert(isequal(front_row(matrix,value),y_correct))\r\n\r\n%%\r\nmatrix=magic(5);\r\nvalue=3;\r\nmatrix(3,2)=value;\r\ny_correct=[3 13 20 22 4; 12 19 21 3 10; 18 25 2 9 11; 24 1 8 15 17; 5 7 14 16 23];\r\nassert(isequal(front_row(matrix,value),y_correct))\r\n\r\n%%\r\nmatrix=magic(7);\r\nvalue=500;\r\nassert(isequal(front_row(matrix,value),matrix))","published":true,"deleted":false,"likes_count":4,"comments_count":1,"created_by":1615,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":156,"test_suite_updated_at":"2014-08-08T17:54:32.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-08-08T17:46:02.000Z","updated_at":"2026-03-31T08:59:33.000Z","published_at":"2014-08-08T17:54:32.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eYou are given a matrix followed by a single number. Your object is to write a script that will shift the matrix around so that the number you are given is in the (1,1) position of the matrix. For example, if you start with the magic(4) 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[     16     2     3    13\\n      5    11    10     8\\n      9     7     6    12\\n      4    14    15     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\u003eand the number 6, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     6    12     9     7\\n    15     1     4    14\\n     3    13    16     2\\n    10     8     5    11]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf there is more than one instance of the number, use the one in the leftmost column. If there is more than one in that column, use the one in the uppermost row. If your input is a modified magic(4)\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[    16     2     3    13\\n     6    11    10     8\\n     9     7     6    12\\n     6    14    15     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\u003eand you need to put 6 in the upper left corner, your output should be:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     6    11    10     8\\n     9     7     6    12\\n     6    14    15     1\\n    16     2     3    13]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf the input number isn't in the matrix, return the original matrix. Good luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1853,"title":"Enlarge array","description":"Given an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q columns.\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  A = [1 2 3\r\n       4 5 6\r\n       7 8 9]\r\n  sz = [3 2]\r\n\r\nthen\r\n\r\n  B = [1 1 2 2 3 3\r\n       1 1 2 2 3 3\r\n       1 1 2 2 3 3\r\n       4 4 5 5 6 6\r\n       4 4 5 5 6 6\r\n       4 4 5 5 6 6\r\n       7 7 8 8 9 9\r\n       7 7 8 8 9 9\r\n       7 7 8 8 9 9]","description_html":"\u003cp\u003eGiven an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q columns.\u003c/p\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eA = [1 2 3\r\n     4 5 6\r\n     7 8 9]\r\nsz = [3 2]\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003eB = [1 1 2 2 3 3\r\n     1 1 2 2 3 3\r\n     1 1 2 2 3 3\r\n     4 4 5 5 6 6\r\n     4 4 5 5 6 6\r\n     4 4 5 5 6 6\r\n     7 7 8 8 9 9\r\n     7 7 8 8 9 9\r\n     7 7 8 8 9 9]\r\n\u003c/pre\u003e","function_template":"function B = enlarge(A,sz)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = randi(100);\r\nsz = [randi(100) 1];\r\nB_correct = repmat(A,sz);\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = randi(1000);\r\nsz = [1 randi(1000)];\r\nB_correct = repmat(A,sz);\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = eye(3);\r\nsz = [2 4];\r\nB_correct = [1 1 1 1 0 0 0 0 0 0 0 0;\r\n             1 1 1 1 0 0 0 0 0 0 0 0;\r\n             0 0 0 0 1 1 1 1 0 0 0 0;\r\n             0 0 0 0 1 1 1 1 0 0 0 0;\r\n             0 0 0 0 0 0 0 0 1 1 1 1;\r\n             0 0 0 0 0 0 0 0 1 1 1 1];\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = magic(4);\r\nsz = [3 3];\r\nB_correct = [16 16 16 2 2 2 3 3 3 13 13 13;\r\n             16 16 16 2 2 2 3 3 3 13 13 13;\r\n             16 16 16 2 2 2 3 3 3 13 13 13;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             5 5 5 11 11 11 10 10 10 8 8 8;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             9 9 9 7 7 7 6 6 6 12 12 12;\r\n             4 4 4 14 14 14 15 15 15 1 1 1;\r\n             4 4 4 14 14 14 15 15 15 1 1 1;\r\n             4 4 4 14 14 14 15 15 15 1 1 1];\r\nassert(isequal(enlarge(A,sz),B_correct))\r\n\r\n%%\r\nA = (-99:0)';\r\nsz = [1 100];\r\nB = enlarge(A,sz);\r\nassert(all(all(bsxfun(@minus,B,A)==0)))","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":4793,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":302,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-08-29T17:58:23.000Z","updated_at":"2026-02-21T20:59:42.000Z","published_at":"2013-08-29T17:58:23.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven an m-by-n numeric array (A) and a 1-by-2 vector (sz) indicating the dimensions [p q] to enlarge each element, return an (m*p)-by-(n*q) array (B) in which each element of A has been replicated in p rows and q 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\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:rPr\u003e\u003cw:b/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eExample\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[A = [1 2 3\\n     4 5 6\\n     7 8 9]\\nsz = [3 2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethen\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[B = [1 1 2 2 3 3\\n     1 1 2 2 3 3\\n     1 1 2 2 3 3\\n     4 4 5 5 6 6\\n     4 4 5 5 6 6\\n     4 4 5 5 6 6\\n     7 7 8 8 9 9\\n     7 7 8 8 9 9\\n     7 7 8 8 9 9]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1898,"title":"Too Many Zeros, Dump Them!","description":"Sometimes when I create a matrix, I use this syntax:\r\n\r\n a = zeros(1000,1000);\r\n\r\nBut when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east of the matrix.\r\n\r\nFor example:\r\n  \r\n a1 = [1 2 0;\r\n       0 3 0;\r\n       0 0 0];\r\n\r\nI want to get a new matrix ,that is:\r\n\r\n b1 = [1 2;\r\n       0 3];\r\n\r\nAnother example:\r\n\r\n a2 = [1 2 0 4 0;\r\n       2 3 0 5 0;\r\n       3 4 0 6 0;\r\n       1 0 0 0 0];\r\n\r\n b2 = [1 2 0 4;\r\n       2 3 0 5;\r\n       3 4 0 6;\r\n       1 0 0 0];\r\n\r\nGood Luck!\r\n","description_html":"\u003cp\u003eSometimes when I create a matrix, I use this syntax:\u003c/p\u003e\u003cpre\u003e a = zeros(1000,1000);\u003c/pre\u003e\u003cp\u003eBut when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east of the matrix.\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cpre\u003e a1 = [1 2 0;\r\n       0 3 0;\r\n       0 0 0];\u003c/pre\u003e\u003cp\u003eI want to get a new matrix ,that is:\u003c/p\u003e\u003cpre\u003e b1 = [1 2;\r\n       0 3];\u003c/pre\u003e\u003cp\u003eAnother example:\u003c/p\u003e\u003cpre\u003e a2 = [1 2 0 4 0;\r\n       2 3 0 5 0;\r\n       3 4 0 6 0;\r\n       1 0 0 0 0];\u003c/pre\u003e\u003cpre\u003e b2 = [1 2 0 4;\r\n       2 3 0 5;\r\n       3 4 0 6;\r\n       1 0 0 0];\u003c/pre\u003e\u003cp\u003eGood Luck!\u003c/p\u003e","function_template":"function b = ZeroDumping(a)\r\nb=a;\r\nend","test_suite":"%%\r\nx = 0;\r\ny_correct = [];\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = 1;\r\ny_correct = 1;\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = [1 0];\r\ny_correct = 1;\r\nassert(isequal(ZeroDumping(x),y_correct))\r\n\r\n%%\r\nx = [1 0 1 0;\r\n     0 0 1 0];\r\ny_correct = [1 0 1\r\n             0 0 1];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx=[1,0,  -3, 1i,0;\r\n   2,0.3,2i, 0, 0;\r\n   0,0,   0, inf, 0;\r\n   0,0,   0, 0, 1];\r\ny_correct =x;% x(4,5) is useful, I don't want to dump it.\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\t0\r\n0\t0\t0\t0\teps];\r\ny_correct =x;\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[1\t1\t0\t0\t0\r\n    1\t0\t0\t0\t0\r\n    0\t0\t0\t3\t0\r\n    0\t0\t0\t0\t0\r\n    0\t0\t0\t0\t0];\r\ny_correct =[1\t1\t0\t0\r\n            1\t0\t0\t0\r\n            0\t0\t0\t3];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n\r\n%%\r\nx =[1\t1\t0\t0\t0\r\n    1\t0\t0\t0\t0\r\n    0\t0\t0\t3\t0\r\n    0\t0\t0\t0\tinf\r\n    0\t0\t0\t0\t0];\r\ny_correct =[1\t1\t0\t0\t0\r\n\t    1\t0\t0\t0\t0\r\n\t    0\t0\t0\t3\t0\r\n\t    0\t0\t0\t0\tinf];\r\nassert(isequal(ZeroDumping(x),y_correct));\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":7365,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":280,"test_suite_updated_at":"2013-09-27T16:23:12.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-09-27T11:48:40.000Z","updated_at":"2026-02-21T21:15:47.000Z","published_at":"2013-09-27T12:56:24.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSometimes when I create a matrix, I use this syntax:\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 = zeros(1000,1000);]]\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 when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east 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:t\u003eFor example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a1 = [1 2 0;\\n       0 3 0;\\n       0 0 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eI want to get a new matrix ,that is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ b1 = [1 2;\\n       0 3];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAnother example:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ a2 = [1 2 0 4 0;\\n       2 3 0 5 0;\\n       3 4 0 6 0;\\n       1 0 0 0 0];\\n\\n b2 = [1 2 0 4;\\n       2 3 0 5;\\n       3 4 0 6;\\n       1 0 0 0];]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGood Luck!\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1429,"title":"Remove entire row and column in the matrix containing the input values","description":"Remove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by\r\nx =\r\n\r\n     8     1     6\r\n     3     5     7\r\n     4     9     2\r\n\r\nand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. \r\nOutput:[ 1 6;    9 2]\r\n\r\nremember the input value can be vector too !\r\n     ","description_html":"\u003cp\u003eRemove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by\r\nx =\u003c/p\u003e\u003cpre\u003e     8     1     6\r\n     3     5     7\r\n     4     9     2\u003c/pre\u003e\u003cp\u003eand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. \r\nOutput:[ 1 6;    9 2]\u003c/p\u003e\u003cp\u003eremember the input value can be vector too !\u003c/p\u003e","function_template":"function y = mat_remove(x,n)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = magic(3); n=3;\r\ny_correct = [1 6; 9 2];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n\r\n%%\r\nx=eye(9); n=[1 0];\r\ny_correct = [];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n%%\r\nx=ones(8); n=1;\r\ny_correct = [];\r\nassert(isequal(mat_remove(x,n),y_correct))\r\n\r\n%%\r\nx=spiral(3); n=1;\r\ny_correct = [7 9; 5 3];\r\nassert(isequal(mat_remove(x,n),y_correct))","published":true,"deleted":false,"likes_count":10,"comments_count":2,"created_by":1023,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":557,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-04-16T01:20:27.000Z","updated_at":"2026-04-02T21:36:45.000Z","published_at":"2013-04-16T01:22:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eRemove the entire row and column from the matrix containing specific values. The specified value can be a scalar or a vector. For example x is given by x =\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[     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\u003eand I specify an input value of n=3. The value 3 is in 2nd row and 1st column. So the output matrix should remove entire 2nd row and 3rd column. Output:[ 1 6; 9 2]\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eremember the input value can be vector too !\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":42501,"title":"Toeplitize a matrix","description":"Similar to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix Problem 3094. Hankelize a matrix\u003e, now consider Toeplitization of a matrix.\r\n\r\nGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example, \r\n\r\nInput \r\n \r\n   A = [6     3     2     7\r\n\r\n        3     5     1     2\r\n\r\n        3     7    10     2]\r\n\r\nOutput:\r\n\r\n   B = [7     2     2     7 \r\n\r\n        5     7     2     2\r\n\r\n        3     5     7     2]\r\n","description_html":"\u003cp\u003eSimilar to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix\"\u003eProblem 3094. Hankelize a matrix\u003c/a\u003e, now consider Toeplitization of a matrix.\u003c/p\u003e\u003cp\u003eGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example,\u003c/p\u003e\u003cp\u003eInput\u003c/p\u003e\u003cpre\u003e   A = [6     3     2     7\u003c/pre\u003e\u003cpre\u003e        3     5     1     2\u003c/pre\u003e\u003cpre\u003e        3     7    10     2]\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre\u003e   B = [7     2     2     7 \u003c/pre\u003e\u003cpre\u003e        5     7     2     2\u003c/pre\u003e\u003cpre\u003e        3     5     7     2]\u003c/pre\u003e","function_template":"function B = toeplitize(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = 100;\r\nB = 100;\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [9,4;2,3;2,0];\r\nB = [6,4;1,6;2,1];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [7,10,9;5,1,0];\r\nB = [4,5,9;5,4,5];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [6 3 2 7;3 5 1 2;3 7 10 2];\r\nB = [7,2,2,7;5,7,2,2;3,5,7,2];\r\nassert(isequal(toeplitize(A),B))\r\n\r\n%%\r\nA = [3,-1,-10,1,4,2;8,4,0,4,2,0;2,0,-1,10,-3,6];\r\nB = [2,3,-3,3,2,2;4,2,3,-3,3,2;2,4,2,3,-3,3];\r\nassert(isequal(toeplitize(A),B))\r\n","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":149,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2015-08-10T05:48:40.000Z","updated_at":"2026-03-29T07:17:50.000Z","published_at":"2015-08-10T05:49:54.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/3094-hankelize-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 3094. Hankelize a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, now consider Toeplitization 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\u003eGiven an input matrix A, convert it to a Toeplitz matrix B by replacing the diagonal of A with the mean of the respective diagonal. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 = [6     3     2     7\\n\\n        3     5     1     2\\n\\n        3     7    10     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\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[   B = [7     2     2     7 \\n\\n        5     7     2     2\\n\\n        3     5     7     2]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1972,"title":"Convert matrix to 3D array of triangular matrices","description":"Given a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\r\n\r\n* If the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\r\n* You may assume that P\u003c=100\r\n\r\n*Example*\r\n\r\nIf\r\n\r\n  x = 1  7 13\r\n      2  8 14\r\n      3  9 15\r\n      4 10 16\r\n      5 11 17\r\n      6 12 18\r\n\r\nthen\r\n\r\n  y(:,:,1) =  1  2  4\r\n              0  3  5\r\n              0  0  6\r\n\r\n  y(:,:,2) =  7  8 10\r\n              0  9 11\r\n              0  0 12\r\n\r\n  y(:,:,3) = 13 14 16\r\n              0 15 17\r\n              0  0 18\r\n\r\n_NOTE:_ If you are wondering why this seems like a strange task, it is inspired by a genotype-\u003ephenotype mapping I am doing in a genetic algorithm.","description_html":"\u003cp\u003eGiven a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\u003c/p\u003e\u003cul\u003e\u003cli\u003eIf the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\u003c/li\u003e\u003cli\u003eYou may assume that P\u0026lt;=100\u003c/li\u003e\u003c/ul\u003e\u003cp\u003e\u003cb\u003eExample\u003c/b\u003e\u003c/p\u003e\u003cp\u003eIf\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ex = 1  7 13\r\n    2  8 14\r\n    3  9 15\r\n    4 10 16\r\n    5 11 17\r\n    6 12 18\r\n\u003c/pre\u003e\u003cp\u003ethen\u003c/p\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,1) =  1  2  4\r\n            0  3  5\r\n            0  0  6\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,2) =  7  8 10\r\n            0  9 11\r\n            0  0 12\r\n\u003c/pre\u003e\u003cpre class=\"language-matlab\"\u003ey(:,:,3) = 13 14 16\r\n            0 15 17\r\n            0  0 18\r\n\u003c/pre\u003e\u003cp\u003e\u003ci\u003eNOTE:\u003c/i\u003e If you are wondering why this seems like a strange task, it is inspired by a genotype-\u0026gt;phenotype mapping I am doing in a genetic algorithm.\u003c/p\u003e","function_template":"function y = mat2triu3(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = 1:100;\r\ny_correct = shiftdim(x,-1);\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:15,3,[]);\r\ny_correct(:,:,1) = [1 2;0 3];\r\ny_correct(:,:,2) = [4 5;0 6];\r\ny_correct(:,:,3) = [7 8;0 9];\r\ny_correct(:,:,4) = [10 11;0 12];\r\ny_correct(:,:,5) = [13 14;0 15];\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = reshape(1:18,3,[])';\r\ny_correct(:,:,1) = [1 4 10; 0 7 13; 0 0 16];\r\ny_correct(:,:,2) = [2 5 11; 0 8 14; 0 0 17];\r\ny_correct(:,:,3) = [3 6 12; 0 9 15; 0 0 18];\r\nassert(isequal(mat2triu3(x),y_correct))\r\n\r\n%%\r\nx = randi(50,sum(1:100),22);\r\ny = mat2triu3(x);\r\nmask = (y~=0);\r\nxb = reshape(y(mask),[],size(y,3));\r\nassert(isequal(size(y),[100 100 22]))\r\nassert(isequal(x,xb))\r\n\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":135,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-11-07T22:49:47.000Z","updated_at":"2026-03-31T09:10:36.000Z","published_at":"2013-11-07T22:58:51.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eGiven a 2D numeric array x in which each column represents the vectorized form of an upper triangular matrix, return a 3D array y containing the concatenated triangular matrices.\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\u003eIf the size of the input matrix x is MxN, then the size of the output matrix y is PxPxN, where M = sum(1:P)\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\u003eYou may assume that P\u0026lt;=100\u003c/w:t\u003e\u003c/w:r\u003e\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 = 1  7 13\\n    2  8 14\\n    3  9 15\\n    4 10 16\\n    5 11 17\\n    6 12 18]]\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(:,:,1) =  1  2  4\\n            0  3  5\\n            0  0  6\\n\\ny(:,:,2) =  7  8 10\\n            0  9 11\\n            0  0 12\\n\\ny(:,:,3) = 13 14 16\\n            0 15 17\\n            0  0 18]]\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:rPr\u003e\u003cw:i/\u003e\u003c/w:rPr\u003e\u003cw:t\u003eNOTE:\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e If you are wondering why this seems like a strange task, it is inspired by a genotype-\u0026gt;phenotype mapping I am doing in a genetic algorithm.\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":2442,"title":"Magnet and Iron","description":"(Inspired from \u003chttp://www.mathworks.com/matlabcentral/cody/problems/112 Problem 112: Remove the air bubbles\u003e)\r\n\r\nIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\r\n\r\nExample:\r\n\r\n Input =\r\n  \r\n       1    26\r\n       3    26\r\n      26    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\r\n  \r\n Output =\r\n      26    26\r\n       1    26\r\n       3    26\r\n       0     0\r\n     -12   NaN\r\n      26    26","description_html":"\u003cp\u003e(Inspired from \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/112\"\u003eProblem 112: Remove the air bubbles\u003c/a\u003e)\u003c/p\u003e\u003cp\u003eIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\u003c/p\u003e\u003cp\u003eExample:\u003c/p\u003e\u003cpre\u003e Input =\u003c/pre\u003e\u003cpre\u003e       1    26\r\n       3    26\r\n      26    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\u003c/pre\u003e\u003cpre\u003e Output =\r\n      26    26\r\n       1    26\r\n       3    26\r\n       0     0\r\n     -12   NaN\r\n      26    26\u003c/pre\u003e","function_template":"function y = strongMagnet(x)\r\n\r\nend","test_suite":"%%\r\nx = [1 1;1 0;1 26; 26 0; 26 26 ;0 1;1 1]\r\ny_correct =[1    26\r\n     1     1\r\n     1     0\r\n    26     0\r\n     0     1\r\n     1     1\r\n    26    26];\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n\r\n%%\r\nx = 26*ones(26,26);\r\ny_correct = x;\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n\r\n%%\r\nx = zeros(26,26);\r\ny_correct = x;\r\nassert(isequal(strongMagnet(x),y_correct))\r\n\r\n%%\r\nx = [1 26; 3 26; 26 26; 0 0; -12 nan; 26 26]\r\ny_correct = [26    26\r\n     1    26\r\n     3    26\r\n     0     0\r\n   -12   NaN\r\n    26    26];\r\nassert(isequalwithequalnans(strongMagnet(x),y_correct))\r\n\r\n","published":true,"deleted":false,"likes_count":6,"comments_count":2,"created_by":17203,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":136,"test_suite_updated_at":"2014-07-16T17:56:54.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2014-07-16T17:54:30.000Z","updated_at":"2026-03-31T08:57:16.000Z","published_at":"2014-07-16T17:54:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e(Inspired from\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/112\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 112: Remove the air bubbles\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e)\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIron (atomic number = 26) is strongly attracted by magnet. The input matrix contains some iron elements (26). I placed two strong magnetic bars above the top row and below the bottom row. What will be state of the matrix after the iron elements have moved due to attraction? Elements equidistant from both magnets will not change their positions.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/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 =\\n\\n       1    26\\n       3    26\\n      26    26\\n       0     0\\n     -12   NaN\\n      26    26\\n\\n Output =\\n      26    26\\n       1    26\\n       3    26\\n       0     0\\n     -12   NaN\\n      26    26]]\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":3094,"title":"Hankelize a matrix","description":"Similar to \u003chttp://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix Problem 42501. Toeplitize a matrix\u003e, let's consider Hankelization of a matrix.\r\n\r\nGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example, \r\n\r\nInput \r\n \r\n   A = [3     7    10     2\r\n\r\n        3     5     1     2\r\n\r\n        6     3     2     7]\r\n\r\nOutput:\r\n\r\n   B = [3     5     7     2 \r\n\r\n        5     7     2     2\r\n\r\n        7     2     2     7]\r\n\r\n\r\n","description_html":"\u003cp\u003eSimilar to \u003ca href = \"http://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix\"\u003eProblem 42501. Toeplitize a matrix\u003c/a\u003e, let's consider Hankelization of a matrix.\u003c/p\u003e\u003cp\u003eGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example,\u003c/p\u003e\u003cp\u003eInput\u003c/p\u003e\u003cpre\u003e   A = [3     7    10     2\u003c/pre\u003e\u003cpre\u003e        3     5     1     2\u003c/pre\u003e\u003cpre\u003e        6     3     2     7]\u003c/pre\u003e\u003cp\u003eOutput:\u003c/p\u003e\u003cpre\u003e   B = [3     5     7     2 \u003c/pre\u003e\u003cpre\u003e        5     7     2     2\u003c/pre\u003e\u003cpre\u003e        7     2     2     7]\u003c/pre\u003e","function_template":"function B = hankelize(A)\r\n  B = A;\r\nend","test_suite":"%%\r\nA = 100;\r\nB = 100;\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [2,0\r\n     2,3\r\n     9,4];\r\nB = [2,1\r\n     1,6\r\n     6,4];\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [5  1   0\r\n     7  10  9];\r\nB = [5   4   5\r\n     4   5   9];\r\nassert(isequal(hankelize(A),B));\r\n\r\n%%\r\nA = [3 7 10 2\r\n     3 5  1 2\r\n     6 3  2 7];\r\nB = [3 5 7 2\r\n     5 7 2 2\r\n     7 2 2 7];\r\nassert(isequal(hankelize(A),B));\r\n\r\n\r\n%%\r\nA = [2  0  -1 10 -3  6\r\n     8  4   0  4  2  0\r\n     3 -1 -10  1  4  2];\r\nB = [2 4  2  3 -3 3\r\n     4 2  3 -3  3 2\r\n     2 3 -3  3  2 2];\r\nassert(isequal(hankelize(A),B));","published":true,"deleted":false,"likes_count":5,"comments_count":0,"created_by":12569,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":158,"test_suite_updated_at":"2015-10-31T18:03:02.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2015-03-19T14:42:36.000Z","updated_at":"2026-02-27T20:57:57.000Z","published_at":"2015-08-09T21:41:21.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eSimilar to\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://www.mathworks.com/matlabcentral/cody/problems/42501-toeplitize-a-matrix\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eProblem 42501. Toeplitize a matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e, let's consider Hankelization 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\u003eGiven an input matrix A, convert it to a Hankel matrix B by replacing each skew-diagonal of A with its mean. For example,\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\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 = [3     7    10     2\\n\\n        3     5     1     2\\n\\n        6     3     2     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\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[   B = [3     5     7     2 \\n\\n        5     7     2     2\\n\\n        7     2     2     7]]]\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":3075,"title":"Matrix of Multiplication Facts","description":"This is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\r\nThe matrix we were given is:\r\n 21   6\r\n 35  10\r\nThe correct answer is:\r\n 21  3   6\r\n  7  0   2\r\n 35  5  10\r\nThe two numbers touching the 21 are 7 and 3, and 7x3=21.\r\nThe two numbers touching the 35 are 7 and 5, and 7x5=35.\r\nThe two numbers touching the 6 are 2 and 3, and 2x3=6.\r\nThe two numbers touching the 10 are 2 and 5, and 2x5=10.\r\nThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!","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: 441.9px; display: block; min-width: 0px; padding-block-start: 0px; padding-top: 0px; perspective-origin: 407px 220.95px; transform-origin: 407px 220.95px; vertical-align: baseline; \"\u003e\u003cdiv style=\"block-size: 84px; 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 42px; text-align: left; transform-origin: 384px 42px; 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: 368.5px 8px; transform-origin: 368.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThis is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\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: 88.5px 8px; transform-origin: 88.5px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe matrix we were given is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 40.8667px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 20.4333px; transform-origin: 404px 20.4333px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 21   6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 28px 8.5px; tab-size: 4; transform-origin: 28px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 35  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cdiv style=\"block-size: 21px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 10px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 10px; perspective-origin: 384px 10.5px; text-align: left; transform-origin: 384px 10.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 10px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 70px 8px; transform-origin: 70px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe correct answer is:\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgb(247, 247, 247); block-size: 61.3px; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; border-end-end-radius: 4px; border-end-start-radius: 4px; border-start-end-radius: 4px; border-start-start-radius: 4px; border-top-left-radius: 4px; border-top-right-radius: 4px; margin-block-end: 10px; margin-block-start: 10px; margin-bottom: 10px; margin-inline-end: 3px; margin-inline-start: 3px; margin-left: 3px; margin-right: 3px; margin-top: 10px; perspective-origin: 404px 30.65px; transform-origin: 404px 30.65px; margin-left: 3px; margin-top: 10px; margin-bottom: 10px; margin-right: 3px; \"\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 21  3   6\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e  7  0   2\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003cdiv style=\"background-color: rgba(0, 0, 0, 0); block-size: 20.4333px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px; border-end-end-radius: 0px; border-end-start-radius: 0px; border-inline-end-color: rgb(233, 233, 233); border-inline-end-style: solid; border-inline-end-width: 1px; border-inline-start-color: rgb(233, 233, 233); border-inline-start-style: solid; border-inline-start-width: 1px; border-left-color: rgb(233, 233, 233); border-left-style: solid; border-left-width: 1px; border-right-color: rgb(233, 233, 233); border-right-style: solid; border-right-width: 1px; border-start-end-radius: 0px; border-start-start-radius: 0px; border-top-left-radius: 0px; border-top-right-radius: 0px; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; min-block-size: 18px; min-height: 18px; padding-inline-start: 4px; padding-left: 4px; perspective-origin: 404px 10.2167px; transform-origin: 404px 10.2167px; white-space: nowrap; \"\u003e\u003cspan style=\"block-size: auto; border-inline-end-color: rgb(0, 0, 0); border-inline-end-style: none; border-inline-end-width: 0px; border-inline-start-color: rgb(0, 0, 0); border-inline-start-style: none; border-inline-start-width: 0px; border-left-color: rgb(0, 0, 0); border-left-style: none; border-left-width: 0px; border-right-color: rgb(0, 0, 0); border-right-style: none; border-right-width: 0px; display: inline; margin-inline-end: 45px; margin-right: 45px; min-block-size: 0px; min-height: 0px; padding-inline-start: 0px; padding-left: 0px; perspective-origin: 40px 8.5px; tab-size: 4; transform-origin: 40px 8.5px; unicode-bidi: normal; white-space: pre; margin-right: 45px; \"\u003e\u003cspan style=\"margin-inline-end: 0px; margin-right: 0px; \"\u003e 35  5  10\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003cul style=\"block-size: 81.7333px; counter-reset: list-item 0; font-family: Helvetica, Arial, sans-serif; list-style-type: square; margin-block-end: 20px; margin-block-start: 10px; margin-bottom: 20px; margin-top: 10px; perspective-origin: 391px 40.8667px; transform-origin: 391px 40.8667px; margin-top: 10px; margin-bottom: 20px; \"\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 21 are 7 and 3, and 7x3=21.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 35 are 7 and 5, and 7x5=35.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 179px 8px; transform-origin: 179px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 6 are 2 and 3, and 2x3=6.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003cli style=\"background-position-x: 0px; background-position-y: 50%; block-size: 20.4333px; counter-reset: none; display: list-item; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-start: 56px; margin-left: 56px; margin-top: 0px; perspective-origin: 363px 10.2167px; text-align: left; transform-origin: 363px 10.2167px; white-space: pre-wrap; margin-left: 56px; \"\u003e\u003cspan style=\"background-position-x: 0%; background-position-y: 0%; block-size: auto; display: inline; margin-inline-start: 0px; margin-left: 0px; perspective-origin: 187px 8px; transform-origin: 187px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe two numbers touching the 10 are 2 and 5, and 2x5=10.\u003c/span\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ul\u003e\u003cdiv style=\"block-size: 63px; font-family: Helvetica, Arial, sans-serif; line-height: 21px; margin-block-end: 9px; margin-block-start: 2px; margin-bottom: 9px; margin-inline-end: 10px; margin-inline-start: 4px; margin-left: 4px; margin-right: 10px; margin-top: 2px; perspective-origin: 384px 31.5px; text-align: left; transform-origin: 384px 31.5px; white-space: pre-wrap; margin-left: 4px; margin-top: 2px; margin-bottom: 9px; margin-right: 10px; \"\u003e\u003cspan style=\"block-size: auto; display: inline; margin-block-end: 0px; margin-block-start: 0px; margin-bottom: 0px; margin-inline-end: 0px; margin-inline-start: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; perspective-origin: 372px 8px; transform-origin: 372px 8px; unicode-bidi: normal; \"\u003e\u003cspan style=\"\"\u003eThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!\u003c/span\u003e\u003c/span\u003e\u003c/div\u003e\u003c/div\u003e\u003c/div\u003e","function_template":"function y = factor_square(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [21 6 ; 35 10];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [6 8 ; 15 20];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx=[35 42 ; 15 18];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [432 288 ; 288 192];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [21 63 ; 15 45];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\nx = [110 132 ; 130 156];\r\ny=factor_square(x)\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\np=primes(1000);\r\nj=randperm(numel(p));\r\np=p(j(1:4));\r\nx=[p(1)*p(2) p(1)*p(3) ; p(2)*p(4) p(3)*p(4)]\r\ny=factor_square(x)\r\n\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\nassert(size(y,1)==3);\r\nassert(size(y,2)==3);\r\n%%\r\np=primes(100000);\r\np(p\u003c50000)=[];\r\nj=randperm(numel(p));\r\np=p(j(1:4))\r\nx=[p(1)*p(2) p(1)*p(3) ; p(2)*p(4) p(3)*p(4)]\r\ny=factor_square(x)\r\n\r\nassert(all(y(:)==round(y(:))))\r\nassert(isequal(y(2)*y(4),x(1)))\r\nassert(isequal(y(2)*y(6),x(2)))\r\nassert(isequal(y(4)*y(8),x(3)))\r\nassert(isequal(y(6)*y(8),x(4)))\r\n","published":true,"deleted":false,"likes_count":13,"comments_count":6,"created_by":1615,"edited_by":223089,"edited_at":"2023-03-01T15:42:21.000Z","deleted_by":null,"deleted_at":null,"solvers_count":148,"test_suite_updated_at":"2023-03-01T15:42:21.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2015-03-10T13:49:14.000Z","updated_at":"2026-03-29T08:01:57.000Z","published_at":"2015-03-10T13:49:14.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\u003eThis is James's daughter again, sneaking into his Cody account. Thanks to your help in my math class last year, I did great! But now they're giving me even harder problems. This time, they're giving me a 2x2 matrix of numbers, and asking me to make it a 3x3 matrix so the center numbers on each side multiply to the numbers in the corner. It's kinda hard to explain, so I'll just give you the example our teacher gave us in class.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe matrix we were given is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 21   6\\n 35  10]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe correct answer is:\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ 21  3   6\\n  7  0   2\\n 35  5  10]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"ListParagraph\\\"/\u003e\u003cw:numPr\u003e\u003cw:numId w:val=\\\"1\\\"/\u003e\u003c/w:numPr\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 21 are 7 and 3, and 7x3=21.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 35 are 7 and 5, and 7x5=35.\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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 6 are 2 and 3, and 2x3=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\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe two numbers touching the 10 are 2 and 5, and 2x5=10.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003cw:jc w:val=\\\"left\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eThe zero in the middle doesn't really matter, so I don't care what number you put in there. Some of the problems might have more than one answer, but as long as the numbers multiply out correctly, it's a good answer. All of the numbers have to be integers, though. Thanks again for your help!\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":1167,"title":"matrix zigzag","description":"Unfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\r\n\r\n [ 1 2 3 ;\r\n   4 5 6 ;\r\n   7 8 9 ] \r\n\r\nthe resulting 1-D array should be \r\n\r\n [ 1 2 4 7 5 3 6 8 9 ]","description_html":"\u003cp\u003eUnfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\u003c/p\u003e\u003cpre\u003e [ 1 2 3 ;\r\n   4 5 6 ;\r\n   7 8 9 ] \u003c/pre\u003e\u003cp\u003ethe resulting 1-D array should be\u003c/p\u003e\u003cpre\u003e [ 1 2 4 7 5 3 6 8 9 ]\u003c/pre\u003e","function_template":"function y = zigzag(x)\r\n  y = x;\r\nend","test_suite":"%%\r\nx = [1 2; 3 4];\r\ny_correct = [1 2 3 4];\r\nassert(isequal(zigzag(x),y_correct))\r\n\r\n%%\r\nx = [ 1 2 3; 4 5 6; 7 8 9];\r\ny_correct = [ 1 2 4 7 5 3 6 8 9];\r\nassert(isequal(zigzag(x),y_correct))\r\n\r\n%%\r\nx = magic(4);\r\ny_correct = [16 2 5 9 11 3 13 10 7 4 14 6 8 12 15 1];\r\nassert(isequal(zigzag(x),y_correct))","published":true,"deleted":false,"likes_count":12,"comments_count":0,"created_by":9535,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":347,"test_suite_updated_at":null,"rescore_all_solutions":false,"group_id":23,"created_at":"2013-01-04T03:24:14.000Z","updated_at":"2026-03-27T17:34:35.000Z","published_at":"2013-01-04T03:24:30.000Z","restored_at":null,"restored_by":null,"spam":false,"simulink":false,"admin_reviewed":false,"description_opc":"{\"relationships\":[{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/document\",\"targetMode\":\"\",\"relationshipId\":\"rId1\",\"target\":\"/matlab/document.xml\"},{\"relationshipType\":\"http://schemas.mathworks.com/matlab/code/2013/relationships/output\",\"targetMode\":\"\",\"relationshipId\":\"rId2\",\"target\":\"/matlab/output.xml\"}],\"parts\":[{\"partUri\":\"/matlab/document.xml\",\"relationship\":[],\"contentType\":\"application/vnd.mathworks.matlab.code.document+xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?\u003e\\n\u003cw:document xmlns:w=\\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\\"\u003e\u003cw:body\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eUnfold a 2-D matrix to a 1-D array in zig-zag order, e.g., for matrix\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [ 1 2 3 ;\\n   4 5 6 ;\\n   7 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003ethe resulting 1-D array should be\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ [ 1 2 4 7 5 3 6 8 9 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003c/w:body\u003e\u003c/w:document\u003e\"},{\"partUri\":\"/matlab/output.xml\",\"contentType\":\"text/xml\",\"content\":\"\u003c?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\" ?\u003e\u003cembeddedOutputs\u003e\u003cmetaData\u003e\u003cevaluationState\u003emanual\u003c/evaluationState\u003e\u003clayoutState\u003ecode\u003c/layoutState\u003e\u003coutputStatus\u003eready\u003c/outputStatus\u003e\u003c/metaData\u003e\u003coutputArray type=\\\"array\\\"/\u003e\u003cregionArray type=\\\"array\\\"/\u003e\u003c/embeddedOutputs\u003e\"}]}"},{"id":1286,"title":"MatCAT - Reconstruct X from Its X-rays","description":"Consider a matrix x\r\n\r\n x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\r\n\r\nIf we sum x along the rows we get\r\n\r\n row_sums = [3 5 11]\r\n\r\nSumming along the columns gives \r\n\r\n col_sums = [4 7 8]\r\n\r\nMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003chttp://en.wikipedia.org/wiki/X-ray_computed_tomography CAT scan\u003e. Can you put all the bones in the right place?\r\n\r\nAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\r\n\r\nBonus question: Under what circumstances does the answer become unique? Discuss.","description_html":"\u003cp\u003eConsider a matrix x\u003c/p\u003e\u003cpre\u003e x = [ 1 2 0\r\n       0 5 0 \r\n       3 0 8 ]\u003c/pre\u003e\u003cp\u003eIf we sum x along the rows we get\u003c/p\u003e\u003cpre\u003e row_sums = [3 5 11]\u003c/pre\u003e\u003cp\u003eSumming along the columns gives\u003c/p\u003e\u003cpre\u003e col_sums = [4 7 8]\u003c/pre\u003e\u003cp\u003eMetaphorically, we might call these sums \"x-rays\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a \u003ca href = \"http://en.wikipedia.org/wiki/X-ray_computed_tomography\"\u003eCAT scan\u003c/a\u003e. Can you put all the bones in the right place?\u003c/p\u003e\u003cp\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/p\u003e\u003cp\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\u003c/p\u003e","function_template":"function x = matcat(row_sums,col_sums)\r\n  x = 0;\r\nend","test_suite":"%%\r\nrow_sums = [3 5 11];\r\ncol_sums = [4 7 8];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [2 2 2 2 2 6];\r\ncol_sums = [2 3 3 3 3 2];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [65 65 65 65 65];\r\ncol_sums = [65 65 65 65 65];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = [22 34 33];\r\ncol_sums = [15 23 18 21 12];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n\r\n%%\r\nrow_sums = 55;\r\ncol_sums = [1 2 3 4 5 6 7 8 9 10];\r\nx = matcat(row_sums,col_sums);\r\nassert(all(x(:)\u003e=0))\r\nassert(isequal(floor(x),x))\r\nassert(isequal(sum(x,2)',row_sums))\r\nassert(isequal(sum(x,1),col_sums))\r\n","published":true,"deleted":false,"likes_count":10,"comments_count":4,"created_by":7,"edited_by":null,"edited_at":null,"deleted_by":null,"deleted_at":null,"solvers_count":147,"test_suite_updated_at":"2013-02-21T17:46:45.000Z","rescore_all_solutions":false,"group_id":23,"created_at":"2013-02-21T17:25:12.000Z","updated_at":"2026-04-02T21:49:21.000Z","published_at":"2013-02-21T17:46:45.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\u003eConsider a matrix x\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"code\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003e\u003c![CDATA[ x = [ 1 2 0\\n       0 5 0 \\n       3 0 8 ]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eIf we sum x along the rows we 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[ row_sums = [3 5 11]]]\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\u003eSumming along the columns gives\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[ col_sums = [4 7 8]]]\u003e\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eMetaphorically, we might call these sums \\\"x-rays\\\". Your job is to take these x-rays and reconstruct the matrix x being x-rayed, in the fashion of a\u003c/w:t\u003e\u003c/w:r\u003e\u003cw:r\u003e\u003cw:t\u003e \u003c/w:t\u003e\u003c/w:r\u003e\u003cw:hyperlink w:docLocation=\\\"http://en.wikipedia.org/wiki/X-ray_computed_tomography\\\"\u003e\u003cw:r\u003e\u003cw:t\u003eCAT scan\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:hyperlink\u003e\u003cw:r\u003e\u003cw:t\u003e. Can you put all the bones in the right place?\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eAll matrix elements must be non-negative integers. There is no guarantee of a unique answer. I will only check that the row and column sums match the supplied matrix, and that your elements are non-negative integers.\u003c/w:t\u003e\u003c/w:r\u003e\u003c/w:p\u003e\u003cw:p\u003e\u003cw:pPr\u003e\u003cw:pStyle w:val=\\\"text\\\"/\u003e\u003c/w:pPr\u003e\u003cw:r\u003e\u003cw:t\u003eBonus question: Under what circumstances does the answer become unique? Discuss.\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":"group:\"Matrix Manipulation II\"","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":"group:\"Matrix Manipulation II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Matrix Manipulation II\"","","\"","Matrix Manipulation II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da160\u003e":["Matrix Manipulation II"],"#\u003cMathWorks::Search::Field:0x00007fa2b41da0c0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b41d9800\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da3e0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b41da340\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b41da2a0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b41da200\u003e":"group:\"Matrix Manipulation II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da200\u003e":"group:\"Matrix Manipulation II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da160\u003e":["Matrix Manipulation II"]}},"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":"group:\"Matrix Manipulation II\"","current_player":null,"sort":"map(difficulty_value,0,0,999) asc"},"parser":"MathWorks::Search::Solr::QueryParser","directives":{"term":{"directives":{"group":[["group:\"Matrix Manipulation II\"","","\"","Matrix Manipulation II","\""]]}}},"facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da160\u003e":["Matrix Manipulation II"],"#\u003cMathWorks::Search::Field:0x00007fa2b41da0c0\u003e":null},"filters":{"#\u003cMathWorks::Search::Field:0x00007fa2b41d9800\u003e":"\"cody:problem\""},"fields":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da3e0\u003e":1,"#\u003cMathWorks::Search::Field:0x00007fa2b41da340\u003e":50,"#\u003cMathWorks::Search::Field:0x00007fa2b41da2a0\u003e":"map(difficulty_value,0,0,999) asc","#\u003cMathWorks::Search::Field:0x00007fa2b41da200\u003e":"group:\"Matrix Manipulation II\""},"user_query":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da200\u003e":"group:\"Matrix Manipulation II\""},"queried_facets":{"#\u003cMathWorks::Search::Field:0x00007fa2b41da160\u003e":["Matrix Manipulation II"]}},"options":{"fields":["id","difficulty_rating"]},"join":" "},"results":[{"id":1321,"difficulty_rating":"easy"},{"id":2178,"difficulty_rating":"easy-medium"},{"id":2063,"difficulty_rating":"easy-medium"},{"id":1422,"difficulty_rating":"easy-medium"},{"id":42320,"difficulty_rating":"easy-medium"},{"id":2701,"difficulty_rating":"easy-medium"},{"id":1421,"difficulty_rating":"easy-medium"},{"id":2351,"difficulty_rating":"easy-medium"},{"id":2493,"difficulty_rating":"easy-medium"},{"id":1853,"difficulty_rating":"easy-medium"},{"id":1898,"difficulty_rating":"easy-medium"},{"id":1429,"difficulty_rating":"medium"},{"id":42501,"difficulty_rating":"medium"},{"id":1972,"difficulty_rating":"medium"},{"id":2442,"difficulty_rating":"medium"},{"id":3094,"difficulty_rating":"medium"},{"id":3075,"difficulty_rating":"medium"},{"id":1167,"difficulty_rating":"medium"},{"id":1286,"difficulty_rating":"medium-hard"}]}}