File Exchange

image thumbnail


version (2.71 KB) by Rody Oldenhuis
Convert a numeric array to a MATLAB code snippet which generates the array

1 Download

Updated 16 Oct 2018

GitHub view license on GitHub

NOTE: in MATLAB 2014a or newer, use The only difference between this command and my submission is that my version saves the script to a variable, and saves it to a file. However, the command from 2014a is much more versatile, rendering this submission pretty useless unless you have an older version of MATLAB.

TOONELINER Convert numeric array into MATLAB code snippet that would
generate the input array when executed
str = TOONELINER(A) converts the numeric array [A] into a one-line MATLAB
code snippet. When passed through eval() or executed manually, this code
snippet will reproduce the array [A].

>> A = [-4 3 2]; str = toOneLiner(A)
str =
[-4 3 2]

>> A = uint8([-4; 5]); str = toOneLiner(A)
str =
uint8([0; 5])

>> A = randi(4, 1,1,2,2); str = toOneLiner(A)
str =
cat(4, cat(3, 4, 4), cat(3, 1, 4))

>> A = int8(complex(...
randi(255, 1,1,2)-randi(255, 1,1,2), ...
randi(255, 1,1,2)-randi(255, 1,1,2)));
>> str = toOneLiner(A)
ans =
cat(3, int8( 46 + -65i), int8(-128 + 72i))

Care has been taken to ensure that isequal(A,eval(TOONELINER(A))) evaluates to
'true' for at least the following data types/sizes:
- (u)int(8/16/32)
- single
- double

Data may be real or complex, and have any dimension.

Cite As

Rody Oldenhuis (2019). toOneLiner (, GitHub. Retrieved .

Comments and Ratings (3)

First time in docs, R2014a

@OlegKomarov Yes, do you happen to know in what version that became available? So I can put that in the description :)

Yuo are probably aware of which however writes the result to a file.


No code changes; just updated the FEX page title

- Included Oleg's comment into the description

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux