I cannot resist to post some variation of the DEC2BIN theme:
A = dec2bin('8<.''#' - 32) - '0'
A = dec2bin('FJ<51' - 46) - '0'
But finally you can even omit the first subtraction, because DEC2BIN operates on CHAR vectors also, but you cannot type the non-printables directly:
q = [100 101 99 50 98 105 110 40 39 24 28 14 7 3 39 41 45 39 48 39];
clipboard('copy', char(q))
==> Ctrl-v in the command window
>> dec2bin('#####')-'0'
Here the '#' are the non-printables with the ASCII codes [24,28,14,7,3]. You can write them even in a M-file.
4 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3526
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3526
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3547
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3547
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3839
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3839
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3942
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/1881-how-do-i-generate-a-given-matrix-in-one-command#comment_3942
Sign in to comment.