Skip to content

Instantly share code, notes, and snippets.

@soegaard
Created June 10, 2014 15:50
Show Gist options
  • Save soegaard/2fe511173180d6b106a3 to your computer and use it in GitHub Desktop.
Save soegaard/2fe511173180d6b106a3 to your computer and use it in GitHub Desktop.
Print matrix in Matlab style
#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