{"id":17432,"date":"2026-10-16T07:13:16","date_gmt":"2026-10-16T11:13:16","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=17432"},"modified":"2026-10-16T07:13:16","modified_gmt":"2026-10-16T11:13:16","slug":"cprintf-easy-display-of-formatted-colored-text-in-command-window","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2026\/10\/16\/cprintf-easy-display-of-formatted-colored-text-in-command-window\/","title":{"rendered":"cprintf &#8211; Easy display of formatted colored text in Command Window"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Mike's pick this week is <\/span><a href = \"https:\/\/uk.mathworks.com\/matlabcentral\/fileexchange\/24093-cprintf-display-formatted-colored-text-in-command-window\" target=\"_self\"><span class=\"_richTextNode\">cprintf<\/span><\/a><span class=\"_richTextNode\"> by <\/span><a href = \"https:\/\/uk.mathworks.com\/matlabcentral\/profile\/authors\/642467\" target=\"_self\"><span class=\"_richTextNode\">Yair Altman<\/span><\/a><span class=\"_richTextNode\">.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I recently took a <\/span><a href = \"https:\/\/blogs.mathworks.com\/matlab\/2026\/10\/12\/enhanced-output-in-the-matlab-command-window-in-r2026b\/\" target=\"_self\"><span class=\"_richTextNode\">deep dive into some new MATLAB functionality<\/span><\/a><span class=\"_richTextNode\"> that allows you to use ANSI escape sequences to display formatted text using the built in <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>fprintf<\/span><span class=\"_richTextNode\"> command. While the syntax used is standard, it's also arcane!<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potwCprintf_1.png\" width = \"486\" height = \"123\" alt = \"\" style = \"vertical-align: baseline; width: 486px; height: 123px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">Yair Altman's <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>cprintf<\/span><span class=\"_richTextNode\"> command uses ANSI escape escape sequences under the hood on modern versions of MATLAB and provides a user-friendly way of specifying the formatting. However, it also works on older versions of MATLAB too using alternative techniques and has been in use for many years with over 30,000 downloads at the time of writing.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I'm using MATLAB R2026b so can easily install it using <\/span><span class=\"_richTextNode\" style=' font-family: monospace;'>mpminstall<\/span><\/div><div style=\"background-color: #F5F5F5; margin: 10px 0 10px 0;\"><div class=\"wpfixed-code-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"MATLAB code\" style=\"width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; overflow-x: auto !important; overflow-y: hidden !important; padding-bottom: 0px;\"><div class=\"wpfixed-code-lines\" style=\"width: max-content; min-width: 100%; box-sizing: border-box;\"><div class=\"wpfixed-code-line\" style=\"overflow: visible !important;\"><div  style = 'border-left: 0px none rgb(33, 33, 33); border-right: 0px none rgb(33, 33, 33); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 21px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace, Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; text-indent: 0px; ; overflow: visible !important;'><span style=\"white-space: pre\"><span >mpminstall(<\/span><span style=\"color: rgb(167, 9, 245);\">\"cprintf\"<\/span><span >,Prompt=false)<\/span><\/span><\/div><\/div><\/div><\/div><div class=\"inlineWrapper outputs\"><div  style = 'color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper disableDefaultGestureHandling embeddedOutputsTextElement\" uid=\"400DD20C\" prevent-scroll=\"true\" data-testid=\"output_0\" style=\"width: 1321.14px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\" tabindex=\"-1\"><div class=\"textElement eoOutputContent\" tabindex=\"-1\" data-previous-available-width=\"1284\" data-previous-scroll-height=\"179\" data-hashorizontaloverflow=\"false\" role=\"article\" aria-roledescription=\"Use Browse Mode to explore \" aria-description=\"text output \" style=\"max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;\">You will be accessing content made available under separate license terms.\r\nLicense terms are available in the package installation folder.\r\n\r\nThe following packages will be installed:\r\n    cprintf@1.23.0  (Repository: File Exchange Repository)\r\nFetching package 'cprintf@1.23.0' ...Done.\r\nExtracting package 'cprintf@1.23.0' ...Done.\r\n\r\nSuccessfully installed the following packages:\r\n    cprintf@1.23.0  (help)\r\n\r\nInstallation complete.<\/div><\/div><\/div><\/div><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span class=\"_richTextNode\">I'll defer to the <\/span><a href = \"https:\/\/uk.mathworks.com\/matlabcentral\/fileexchange\/24093-cprintf-display-formatted-colored-text-in-command-window\" target=\"_self\"><span class=\"_richTextNode\">File Exchange page<\/span><\/a><span class=\"_richTextNode\"> for full details of everything that cprintf can do but here are a few examples<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potwCprintf_2.png\" width = \"696\" height = \"121\" alt = \"\" style = \"vertical-align: baseline; width: 696px; height: 121px;\"><\/img><\/div>\r\n<\/div><script id=\"wpfixed-code-scroll-layout\">\r\n(function () {\r\n    \"use strict\";\r\n\r\n    function initialize() {\r\n        if (window.wpfixedCodeScrollLayout) {\r\n            window.wpfixedCodeScrollLayout.refresh();\r\n            return;\r\n        }\r\n\r\n        var pending = false;\r\n        var observed = new WeakSet();\r\n        var observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(schedule) : null;\r\n\r\n        function update() {\r\n            pending = false;\r\n            document.querySelectorAll(\".wpfixed-code-scroll\").forEach(function (group) {\r\n                var lines = group.querySelector(\".wpfixed-code-lines\");\r\n                if (!lines) {\r\n                    return;\r\n                }\r\n                if (observer && !observed.has(group)) {\r\n                    observer.observe(group);\r\n                    observer.observe(lines);\r\n                    observed.add(group);\r\n                }\r\n                \/\/ Overlay scrollbars need clearance only when there is overflow.\r\n                var padding = group.scrollWidth > group.clientWidth + 1 ? \"18px\" : \"0px\";\r\n                if (group.style.paddingBottom !== padding) {\r\n                    group.style.paddingBottom = padding;\r\n                }\r\n            });\r\n        }\r\n\r\n        function schedule() {\r\n            if (!pending) {\r\n                pending = true;\r\n                requestAnimationFrame(update);\r\n            }\r\n        }\r\n\r\n        window.wpfixedCodeScrollLayout = { refresh: schedule };\r\n        window.addEventListener(\"resize\", schedule);\r\n        window.addEventListener(\"load\", schedule, { once: true });\r\n        if (document.fonts && document.fonts.ready) {\r\n            document.fonts.ready.then(schedule);\r\n        }\r\n        schedule();\r\n    }\r\n\r\n    if (document.readyState === \"loading\") {\r\n        document.addEventListener(\"DOMContentLoaded\", initialize, { once: true });\r\n    } else {\r\n        initialize();\r\n    }\r\n}());\r\n<\/script><script type=\"text\/javascript\">var css = '._richTextNode {white-space: break-spaces;} \/* Copyright 2014-2025 The MathWorks, Inc. *\/\/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsErrorElement .diagnosticMessage-errorType {    overflow: auto;} .embeddedOutputsErrorElement.inlineElement {} .embeddedOutputsErrorElement.rightPaneElement {} \/* Copyright 2014-2025 The MathWorks, Inc. *\/\/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsWarningElement {    min-height: 18px;    max-height: 550px;} .embeddedOutputsWarningElement .diagnosticMessage-warningType {    overflow: auto;} .embeddedOutputsWarningElement.inlineElement {} .embeddedOutputsWarningElement.rightPaneElement {} \/* Copyright 2015-2025 The MathWorks, Inc. *\/\/* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip *\/.diagnosticMessage-wrapper {    \/* Since this selector may be used outside RTC Container without RTC semantic variables, a    default value is used. An example here is the App Designers alert tooltip. *\/    font-family: var(--rtc-output-font-family, Menlo, Monaco, Consolas, \"Courier New\", monospace);    font-size: var(--rtc-output-font-size, 12px);} .diagnosticMessage-wrapper.diagnosticMessage-warningType {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));} .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    \/*This fallback value will be used for appdesigner warnings*\/    color: var(--rtc-warning-output-color, var(--mw-color-matlabWarning));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: var(--mw-color-matlabWarning) !important;} .diagnosticMessage-wrapper.diagnosticMessage-errorType {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));} .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    \/*This fallback value will be used in appdesigner error tooltip text*\/    color: var(--rtc-error-output-color, var(--mw-color-matlabErrors));    text-decoration: underline;} .rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: var(--mw-color-matlabErrors) !important;} .diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: pre-wrap;} .diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: pre;} \/* Copyright 2014-2025 The MathWorks, Inc. *\/.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: pre;    word-wrap:  initial;    min-height: 18px;    max-height: 550px;} .embeddedOutputsTextElement .textElement,.embeddedOutputsVariableStringElement .textElement {    overflow: auto;} .textElement,.rtcDataTipElement .textElement {    padding-top: 2px;} .embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {} .inlineElement .textElement {} .embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;} .rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;} .embeddedOutputsVariableStringElement { width: initial !important; }'; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potwCprintf_2.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Mike's pick this week is cprintf by Yair Altman.I recently took a deep dive into some new MATLAB functionality that allows you to use ANSI escape sequences to display formatted text using the built... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2026\/10\/16\/cprintf-easy-display-of-formatted-colored-text-in-command-window\/\">read more >><\/a><\/p>","protected":false},"author":176,"featured_media":17430,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-17432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-picks"],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/17432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/176"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=17432"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/17432\/revisions"}],"predecessor-version":[{"id":17433,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/17432\/revisions\/17433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/17430"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=17432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=17432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=17432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}