File Exchange

## toOneLiner

version 1.1.0.1 (2.71 KB) by Rody Oldenhuis

### Rody Oldenhuis (view profile)

Convert a numeric array to a MATLAB code snippet which generates the array

Updated 16 Oct 2018

NOTE: in MATLAB 2014a or newer, use matlab.io.saveVariablesToScript(). The only difference between this command and my submission is that my version saves the script to a variable, and matlab.io.saveVariablesToScript() 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].
Examples:

>> 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 (2020). toOneLiner (https://www.github.com/rodyo/FEX-toOneLiner), GitHub. Retrieved .

Oleg Komarov

### Oleg Komarov (view profile)

First time in docs, R2014a

Rody Oldenhuis

### Rody Oldenhuis (view profile)

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

Oleg Komarov

### Oleg Komarov (view profile)

Yuo are probably aware of matlab.io.saveVariablesToScript() which however writes the result to a file.