Created
June 10, 2014 15:50
-
-
Save soegaard/2fe511173180d6b106a3 to your computer and use it in GitHub Desktop.
Print matrix in Matlab style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require math) | |
(define old-printer (array-custom-printer)) | |
(define (matrix-printer A name port mode) | |
(cond | |
[(not (matrix? A)) (old-printer A name port mode)] | |
[else (for ([r (matrix-rows A)]) | |
(display "[" port) | |
(for ([x (array->vector r)]) | |
(display (~a " " x) port)) | |
(display "]\n" port))])) | |
(array-custom-printer matrix-printer) | |
(matrix [[1 2] [3 4]]) | |
; Output: | |
[ 1 2] | |
[ 3 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment