Effortlessly Display a Matrix of Numbers in Mathematica | Quick Solution

  • Context: Mathematica 
  • Thread starter Thread starter iva_bg
  • Start date Start date
  • Tags Tags
    Mathematica Table
Click For Summary
SUMMARY

The discussion focuses on displaying a matrix of numbers in Mathematica with each entry formatted as a percentage. The user seeks a solution to automate the formatting process without manual input for each matrix entry. The provided solution utilizes the function FormatNumber[x_] := ToString[x] <> "%" combined with Map[FormatNumber, mat, {2}] to achieve the desired output. This method effectively formats the matrix entries and displays them in a user-friendly manner using MatrixForm.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of matrix operations in Mathematica
  • Basic knowledge of function definitions in Mathematica
  • Experience with formatting outputs in Mathematica
NEXT STEPS
  • Explore advanced matrix manipulation techniques in Mathematica
  • Learn about custom formatting functions in Mathematica
  • Investigate the use of MatrixForm for enhanced output presentation
  • Research additional data visualization options in Mathematica
USEFUL FOR

This discussion is beneficial for Mathematica users, data analysts, and educators looking to efficiently format and display numerical data in matrix form.

iva_bg
Messages
8
Reaction score
0
Hello,

does anyone have an idea how easily to display a matrix of numbers such that each entry, for example 3, is displayed (3%), without having to type it manually, i.e. a command to do it for each entry in my output matrix?

Thanks a lot!
 
Physics news on Phys.org
Maybe something like
Code:
(* I suppose you already have a matrix mat, e.g.: *)
mat = {{1, 2, 3}, {4, 5, 6}, {7, 8,9}}; 

FormatNumber[x_] := ToString[x] <> "%"

Map[FormatNumber, mat, {2}]
% // MatrixForm
 
Thank you, this is fantastic!
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
10K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K