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].
>> A = [-4 3 2]; str = toOneLiner(A)
[-4 3 2]
>> A = uint8([-4; 5]); str = toOneLiner(A)
>> A = randi(4, 1,1,2,2); str = toOneLiner(A)
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)
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:
Data may be real or complex, and have any dimension.
Rody Oldenhuis (2019). toOneLiner (https://www.github.com/rodyo/FEX-toOneLiner), GitHub. Retrieved .
No code changes; just updated the FEX page title
- Included Oleg's comment into the description