value2str

value2str(value, simplify)

VALUE2STR Convert MATLAB values or tables to evaluable string representations

Usage:

s = value2str(x) s = value2str(x, simplify)

Inputs:

x : any - scalar, vector, matrix, cell, string, logical, or table – required simplify : logical - simplify scalar numeric values to fractions, pi multiples,

or exp notation (default: true)

Outputs:

s : char or table - string representation of x, or table of strings if x is a table

Notes

  • Converts scalars, arrays, strings, logicals, cells, and tables into strings that can be evaluated using eval in MATLAB.

  • Handles numeric vectors or matrices inside table cells as single strings.

  • Fully parallelizable for table inputs using parfor.

  • Optional simplification converts scalar numbers to fractions, multiples of pi, or exp(x) when the decimal representation exceeds 4 characters.

  • Preserves exp() and pi forms over aggressive fraction conversion.

Example

value2str(0.5) % ‘1/2’ value2str(pi/6) % ‘(1*pi)/6’ value2str([1 2; 3 4]) % ‘[1 2;3 4]’ value2str({‘a’, [1 2 3], true}) % ‘{‘’a’’, [1 2 3], true}’ value2str(1/3, false) % ‘0.333333333333333’

See also: double2fracstr, double2pifracstr, double2estr, table2csv, csv2table

∿∿∿ Prerau Laboratory MATLAB Codebase · sleepEEG.org ∿∿∿