PGM image not opening - pgm

I have a pgm file which is well formatted like this
P2
# CREATOR: GIMP PNM Filter Version 1.1
19 19
0 71 73 74 73 73 74 73 71 70 71 74 72 69 68 71 72 66 69
70 70 74 70 69 69 69 69 71 68 70 72 66 70 71 69 65 68 69
66 72 73 74 74 73 70 73 72 66 70 68 67 68 68 68 67 66 69
66 72 78 74 74 73 71 71 70 70 68 70 66 69 66 65 66 62 62
62 72 76 72 73 75 72 71 68 74 71 68 66 70 65 67 62 56 57
66 70 72 71 72 69 72 73 74 69 65 66 60 64 68 93 99 139 225
240 68 71 70 70 69 70 71 64 64 46 60 57 86 153 206 233 240 244
245 72 69 70 68 67 68 68 68 61 58 82 178 229 236 236 229 238 244
245 74 67 67 70 68 66 69 65 64 97 218 240 242 235 234 240 243 244
244 75 74 73 72 69 68 73 74 128 223 239 242 239 242 243 242 244 241
244 72 76 74 72 69 71 68 83 155 234 242 240 237 242 237 241 240 245
243 72 75 75 71 68 69 65 68 127 237 241 240 241 243 245 244 244 245
244 72 71 69 71 66 66 63 63 107 239 240 244 245 245 246 245 246 246
246 72 70 70 67 64 63 60 74 218 242 245 245 245 245 246 246 247 246
245 73 72 71 70 70 66 61 201 241 244 245 246 245 246 247 246 247 246
247 71 69 71 68 63 61 115 236 239 244 244 245 245 246 246 246 246 246
245 78 72 73 73 68 63 167 243 244 244 245 245 245 246 246 246 246 246
245 75 72 69 71 67 61 218 245 245 246 246 246 246 246 246 246 247 246
246 76 72 72 68 65 74 238 246 246 246 247 246 246 246 246 246 246 246
But trying to open it with "visionneur d'images" on ubuntu i get an error :
Please help me.. I don't know what is the issue.

The number after image dimensions is supposed to be the maximum value in the image. You have it as '0'. Scanning quickly through the data, the value should be 247. Just replace the 0 with 247, using a text editor.

Related

Snort logs in OSSIM show hex in payload but I want only the text to be there. Is there a config I can change in Snort?

I am new to snort and I am testing things out with OSSIM. I've installed snort and using rsyslog I am getting snort alerts.log to OSSIM. But the thing is payloads of events in OSSIM show as
length = 219
000 : 31 31 2F 32 35 2F 31 39 2D 31 30 3A 30 34 3A 32 11/25/19-10:04:2
010 : 39 2E 37 38 30 31 32 34 20 20 5B 2A 2A 5D 20 5B 9.780124 [**] [
020 : 31 32 30 3A 31 38 3A 33 5D 20 28 68 74 74 70 5F 120:18:3] (http_
030 : 69 6E 73 70 65 63 74 29 20 50 52 4F 54 4F 43 4F inspect) PROTOCO
040 : 4C 2D 4F 54 48 45 52 20 48 54 54 50 20 73 65 72 L-OTHER HTTP ser
050 : 76 65 72 20 72 65 73 70 6F 6E 73 65 20 62 65 66 ver response bef
060 : 6F 72 65 20 63 6C 69 65 6E 74 20 72 65 71 75 65 ore client reque
070 : 73 74 20 20 5B 2A 2A 5D 20 5B 43 6C 61 73 73 69 st [**] [Classi
080 : 66 69 63 61 74 69 6F 6E 3A 20 55 6E 6B 6E 6F 77 fication: Unknow
090 : 6E 20 54 72 61 66 66 69 63 5D 20 5B 50 72 69 6F n Traffic] [Prio
0a0 : 72 69 74 79 3A 20 33 5D 20 7B 54 43 50 7D 20 31 rity: 3] {TCP} 1
0b0 : 39 32 2E 31 36 38 2E 30 2E 31 36 38 3A 38 30 38 92.168.0.168:808
0c0 : 30 20 2D 3E 20 31 39 32 2E 31 36 38 2E 30 2E 31 0 -> 192.168.0.1
0d0 : 32 32 3A 33 39 31 37 30 22 20 0A 22:39170" .
But I want it to be like
11/25/19-10:04:29.780124 [**] [120:18:3] (http_inspect) PROTOCOL-OTHER HTTP server response before client request [**] [Classification: Unknown Traffic] [Priority: 3] {TCP} 192.168.0.168:8080 -> 192.168.0.122:39170" .
Is there any config in snort I can change to make this happen?
Thanks in advance for any help!

How to apply k-means without normalization and k-means with normalization on my dataset?

I want to calculate the accuracy of my k-means clustering without normalization and k-means clustering with normalization and want to compare the results.
My dataset looks like this:
age chol
63 233
37 250
41 204
56 236
57 354
57 192
56 294
44 263
52 199
57 168
54 239
48 275
49 266
64 211
58 283
50 219
58 340
66 226
43 247
69 239
59 234
44 233
42 226
61 243
40 199
71 302
59 212
51 175
65 417
53 197
41 198
65 177
44 219
54 273
51 213
46 177
54 304
54 232
65 269
65 360
51 308
48 245
45 208
53 264
39 321
52 325
44 235
47 257
53 216
53 234
How can I write the code for it in Matlab and plot it?

MATLAB Serial incorrectly sending values

I am trying to communicate with a StepRocker motor controller/drive using MATLAB. I have figured out how to format their commands and have been able to get it to move to many of commands. Their commands require that the values be sent in a binary format over RS-232. I started running into some issues and started using an Arduino to echo my commands.
I am currently sending the values 1 - 255 just to test sending bytes over the serial channel. I am sending it to an Arduino and reading the bytes back out of the Arduino. All numbers work except for the numbers between 128 and 159. This is problematic since some of my commands require values in this range.
MATLAB Script:
obj = instrfind; delete(obj); % cleanup any lost objects
clear; close force all; clc; % clear the workspace
sM = serial('COM2','BaudRate',9600, 'Terminator', 'CR', 'Timeout', 10);
fopen(sM);
pause(2); % give port time to open
% make list of numbers 1-255, skip 10/13 since they terminate on the
% arduino
cmd = [1:9 11:12 14:255];
% Send command and get echo
fprintf(sM,cmd);
pause(0.5); % give time for echo
echo = fscanf(sM);
uint8(echo)
fclose(sM);
After executing this script I get the following output:
ans =
Columns 1 through 22
1 2 3 4 5 6 7 8 9 11 12 14 15 16 17 18 19 20 21 22 23 24
Columns 23 through 44
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Columns 45 through 66
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
Columns 67 through 88
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
Columns 89 through 110
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
Columns 111 through 132
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 63 63 63 63 63 63 63
Columns 133 through 154
63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
Columns 155 through 176
63 63 63 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
Columns 177 through 198
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
Columns 199 through 220
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
Columns 221 through 242
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
Columns 243 through 254
245 246 247 248 249 250 251 252 253 254 255 13
Looking at the output, you can see that the numbers between 128 and 159 all come through as 63. I am at a loss for what is causing this issue. This is very repeatable, and the problem occurs anytime there is a number in this range, no matter its position in the string, no matter the length of the serial string.
Arduino Code:
bool stringComplete = false;
String inputString = "";
void setup() {
Serial.begin(9600);
}
void loop() {
if (stringComplete) {
Serial.print(inputString);
stringComplete = false;
inputString = "";
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\r') {
stringComplete = true;
}
}
}
Any suggestions or ideas on how to solve this problem?

How can I decrypt this so I can view it

Hex (148 bytes): 3c 68 74 6d 6c 3e 3c 68 65 61 64 3e 3c 2f 68 65 61 64 3e 3c 62 6f 64 79 3e 3c 69 6d 67 20 73 72 63 3d 22 64 61 74 61 3a 69 6d 61 67 65 2f 6a 70 65 67 3b 62 61 73 65 36 34 2c 2f 39 6a 2f 34 41 41 51 53 6b 5a 4a 52 67 41 42 41 51 45 41 57 67 42 61 41 41 44 2f 34 67 78 59 53 55 4e 44 58 31 42 53 54 30 5a 4a 54 45 55 41 41 51 45 41 41 41 78 49 54 47 6c 75 62 77 49 51 41 41 42 2e 2e 2e ... �����ExifII*bj(1r2�i����
'��
'Adobe Photoshop CS4 Macintosh2012-02-06T20:39:30�0220�������Ducky<��-�http://ns.adobe.com/xap/1.0/ ��Adobed����
��^��� !1AQq"a����2BR#�br3�႒�$%��CS��D5!1AQq�a��2B�����"R�br�3��?��ݣW���DB�{6�xֵ�,�=����A���NY>C%�nE^j?��
��;\��So��k���9̇�X���I%4�|�1����m�vC���:G�Y��;}�R�D"���0p1���3�,�^}NVn���)��G�W7y��^�u�Գ��ywҰM�y�y3^�m�,Z�B {�x������d1E;�s���6q�e�~��{ۺ"=��7-�r>�e��t.I�u$���v�SG�qXwҒ�u��M������j��" �<�tW��ą�|�c��ꮖ�����:.��0DO:����RFX��E��4g�e�>Xv״����o�L��sw���c�'���i}I��IYaFz�(�������C�Zu(8�Xky�?����b�\j���#�c��.#s����G��g_i4�K��n�+)^a�..�F]VXQ��B�%�O8��e g�T����HѸ
�T4P���K��j|T�)���Lv��wO�$uq���J��L�l���c��h��2AsO�Ϲs�晝#��u��{�q�t�xN���ɪ�pT############A&z�6�ޠ�����C�#��2\&�xK�����{]ރ��<��"��Ǥ�uO����9�6�x��-�={޶7�ft���hg��sC�Ai��VlĪ������?W��C�m�����63�IN���J7��3q��:G(x>��?�ɥ~
���Ϲ-w ########A��L��u-��qlR;��S�d�_�-������C���˖i?4}��!����kS�t��L�~l&���Q)|��5�����#ݭ�=�U����z3/�6�厫fc\xV��˭�]
��
�
� �F�8~���a��K���2����TI��2��E����]t��Mg�������m�N�*Z�D�������rA0k�70�TD�;K.�����̍�z��&����id�9�Yg��ִ����]c��mc<�j�MSz�Йg�<�44<
G*tre�RQ� 8�^jH#��.�s0b�!� h�7���>�g�-o,M��Z�ֆ�
��|�Ӭ�*��Lc��.{��*I<������FY��_��Z>��t�{"��[8�|��C͗��e}|��F#����kM�&��>��ycI�6=�2V�v��|]�=o_�[O�s���.���V�{LMq�,b�v7��v�ʕ�<]�y�WM"l=�������4��oҶ��J��P�N.qD��Y��d�Qe;��=����N��Ԟ�8���4���_Ok/ַ,ȳ����x�o(5����������j�㥸K.ߨ�/�Y�ɓ������VgX##A�Ϩ�7>�/m�m��:{7}����ߪW'5<��κ��p�{5�<'�G0�4Ddisi���ݎ��*km'V}�iŒ���O]��c�l���+�+y��Q��5�a��-1�] ��H��Ԡgb��oX��J��E��I��,�#:������k'l׎�J�,�m���������(�����#����AA4c�% ��U�Z:sfw~A�K1����[����M�и�Š���}��)�%����q�io�{�c�i��ۿ
�V2�e��:�[�9�S�w?���o�����[D�Lr�bc��84�ujI��+%���"vH{sa�J�O��q��%y�md�ZO�*��Y���1�ʣ!hPP��%��#�$ Ɨ-x(�k.z�6W|���h��
�\�a$y���Y��V�N���v�9$<��)�zf?�rdW�n��4���4�vB��m�
�K�i�ٲ���~�#j�.6�Z֍hA�=���na�F�7�_rn�҂�WAV�PP\�5�<���1�o�$#B�x�{�-�df!��,�$��qAv<~fWn�尷�F�������˧wk�#�6+X"��h�
�ATA�08iM�|ET�;���:�J4�8(��/RX�ַQH̾k=��U�zkI������#Og&�EF��+��ЈU�-pp�
G��]7��-���bv���ǟc�Gs�f��"_J�f���x���+6D�_u�5�t��L��b�[�\�N������,�<��sz��6���+�������dw�vN��� ��$�$��4�a��h�[9KK|v�.�et�7���.�8�\qѽ��I��i�~���Gs�}C���G�|�B+Z�> �=ȶ,�K,��pm�-�I�����6o>ں�=��c�Fn>Pw�'�{˨�����(A�(����^zצ��tI:i��_��1:����p�UksmŬ�H�k���e4tV����N�:�M�h#MP��z��ܑ-����q��2��PI;�
(CV$����Y��1�q/�)n�ᴶm-�c)�#D�q��hЃ�{d;Z<�PlV�vҠ �A�;���Pcϔ��Ѻ�6�m�M{�w��'$X��;���<�k�s�]��ȣ��͝���: ʏ� s�˩��}(C�C�4A���Y[�C��#AT!k�w��p>*�k�W���v�5Ӵp�� �}e�������i]<M&��Lt������iq7����ԁ����s2�KL<S��Y�^�Z�########A)z=�Dg������L�ַ.���-q��|�y[{l�^���N0���d���Jzc��1���
�=�N�aTH�����P0�5 d���M�[�5��?Wu+�w�,���.n���Ɵ�+�sG��%��fWu�G�\f4�6ٜZKOC��u�9��[�Oc�ɓ'����w��<R�w���~�Xt�5nl�i�E��WO1�G�a͚)�+�u:�q�<��N/��no�滺��q;̒��R\�RJ���:��6���fV* ������V�CS�����;U���~׵�z4���_�>���G����ʭ�uzX�s[�����Jb:��K�� ~�OhMd�I��;����'�4����[V��ꤴ�����0�)�F�͗#�$���E�Av�Eh�7�^���!�\H5;�R7v��~?�imj)P*Pd�Fm �-�C�AguI�y���Ν��K��EG'��AV�ݹ�R��⍏�v���t�y�l�>�=���Mnn�ioA��GrL��^��&����y��C�Q׳O��X���R��6�J����5�P
#�P*��T
� �-q���t�J��*P�ӡ~�� |��cG
9� p��C�2C�x��ɏZ}*�R�������B}%u�9-��G��?�h��%澥��H��.�j�������������oS3�?umj�6$���o/�5���2un��,�ھ�ǩ��1:Ӷ'��}0������Ka�t�7A�법����&X�6������׏sI���D��d�a��'��E���<aS��~�h��^�X��=�Ve��o� �i-�b��;�w�s��9���9�&2[�aKS���a����{���㧺~_͵���;W�.��*x�ro�_j�<5���ϥb�>o������[������\H�a��m���Q3���V5��o[zᏳk��p��Z���g�4�s��Z�wQ�{��+��]�g��r9+ܕ䗗�:{�N�$y�%h��β򗽭3kN�,e
�-�\�o�W�|Or�����p_-���e��җ9K����m������ ����J��ycGж[XJ)���2�Zh��Fi��fmtm]R+��F��i�>h=�A�s_��W�$
t.B[C�:Ӛ
1�Iv�M���H��Y�Or'pv�N���M�8;Zº��<3hv�֤�b#Ѯ�֨.7q���~H(���[� ��_��ۏ�l&,��Ĭ%��wD���z��<��:����x��XL�5d#AP�ֱ����{u��)C�?��
%hs���yK)i�y��X�Mu�Ej���������]sa'�E3���oȭ\�֞T�9�����7L�2�뜖R��ٻ����F=�4��5�gFLx���9����
��}:#D�#��3x�ln���z}�LE}�Y_z����!�����ZG����Rs}(�4�ƽۤ������;��QbŚi��lz�]���5�N �
�gEߵ��I1����\����0�wU�S��oo�ZO�s���:.f�fnΟ�3~ �������-��}��y�p�s�vT�٘��i%'-{�6�[x���i��c�;W���}Ӝ#��#�����i
<�{m^S6�~�ծhp5TaYݘ�I�A��7�k�id��챡���]�Z{�p�y��rG���̠��b
��H��ݍ�
kY�Q�c�.O��-��Oen�ضW���U��Kϩ���3��ҭ�~�uE�Z-�s\��ɩc���iX�:����׍�m�CӞ��a���Iv�®m�ul���wrخ8�N�,4�R"��J-�!"lv��1���pWёG4��;t;��#D�h�hC�S���7p�=�.m�k����
8��a�j�̯��PWy4�%�b�&��}ćO.^��\�:'q�:�zvѻ�j3�߹�}����M��m;��A��i6�*(��ڂ��og�
�Q����H|/itN�m����$��<���9Fk4g�4!̽zɱ�N�HI8瘪���7��c~2�a��O�Vx"]�5
ꪀ��+T|F�ô����;Oz�.�#퍐�L��$q#�k�ٚci;CO�H�ޡ/��eśN������\�)�ӗ�Se\u�j�)���͜�{X��h'���ںN����,���J�\#######A#�g�ޟ���wSf�s|�-�8�t�~Ԏ.=��8/J�n�K��O��i�٤xqt=K��f���nl�w4��[I���[���u��i��z�܇�on��廻��\���ey���ĕ�3��/3kM�fgY��
�21�s����[��{�lK�#
b5��&��s����?����������A�Ӵ�#.��V8��|�Ï[Ε�|���]7T��-�<�8���i_i$��Yry��o��7�\��ͬm!76���O�)���ˏ����&u���v��?.?%��k�f�����8��W�E�p,�ᇘn��g�b�]�v˭���G�i���Æ��1�jZ+!�Y낕�����X������<��0����0�
~�hX��C}Vv����_�)J�t�� �>:����?h��<�l�c�k��ʠC��Q�T
q�AV� �N-51���[J4�p�>���4T��e���lev�0���u�D3-�y� 73Enʅ��O���+��5��q�]��yx�/�� ��kov�X&�>�P*��?ז�o�ɯ��!�?��o��?��P��&��>��"<��l�5� g�����
����H��ntDo<�tU���z+�_���v����/�����Y�i�,��� �q}il��2&�opoҚ
�^�!y� w0�4���
tF�~����rc���lm.s�4p"�[NuQ$:�H�������v�,W�����
�����㺣�w
n��.;����v�H'��8 �=um��-s��N.A�f���{A�۪�np��;��=4G�0�0��>Y�Q�U����xϨb��k�H��wX!g������FS���lsK0��%���}8
���<#[:]3$�'쯟/ˬ�Q��[���p�N5����ݧ��7=���T�����S��G����?f�?7�9�
k#=��byΞ�����r��k�~4f�)�o��ö���}������:A��0�~�+�܏g�lR0����kӣᘙ�m7k����r_�p����_�ܮ��AO.��M=N�
z\�ql]�����%+��t�
�P[Jk�C����t�{*����uk�j�a�����̊Z��fA]���?q yu|ָ�ͣe=� �}<��Hm���J��6~��A�G��5�X,c�b��R9R�Z>h/Gi���__\\�^%�ckNb6��A��~���<���J��1NJA
ٱ�e<��}xm��� �}?",L��>+ɿF�w�Kj�3��n�K|#V�h��2��)�+_b���!�;rۉZȋ]��M;%D�/��3-�.4ҳ�C������-/�p�cn��#ExU�R�U[�hu��.siͩpӈ�uH�l���r7SW��.>lhR�g��[��� ��+mR7�n�,�GfI��:��]
E[�)$;� U��
I'm not sure what you mean by decrypting this so you can view it. It looks like the contents of an image file. Try opening this file with an image viewer such as MS Paint, Adobe Photoshop or try uploading it to https://pixlr.com/editor. You might have to change the file extension for this to work (try PSD).
In case you're not interested in the image but actually the contents of the file, encoding is not really your problem here since this is not a text file but a binary file. Its contents don't represent characters but are contents of data structures used by Photoshop to represent an image.

Appending specified vector elements to all permutations of the vector, 'mostly random' row ordering for nearby integers etc

In Matlab
1) If I have a vector, say [1 2 3] then I'm looking to create a matrix that contains every permutation of the vector, with another column appended containing, for each permutation, the first element of the original vector. I'd then like this matrix to be appended (by row) to another where the appended column is the second element. Then following this the same thing with the third. i.e.:
3 2 1 1
3 1 2 1
2 3 1 1
2 1 3 1
1 2 3 1
1 3 2 1
3 2 1 2
3 1 2 2
2 3 1 2
2 1 3 2
1 2 3 2
1 3 2 2
3 2 1 3
3 1 2 3
2 3 1 3
2 1 3 3
1 2 3 3
1 3 2 3
This is a long form way of writing it but I'm certain that someone here will be able to write it in a very concise way instead:
a = [1 2 3]; b = perms(a);
c = [a(1); a(1); a(1); a(1); a(1); a(1)] ;
d = [a(2); a(2); a(2); a(2); a(2); a(2)] ;
e = [a(3); a(3); a(3); a(3); a(3); a(3)] ;
f = [ c; d; e ]
g = [ b; b ; b]
h = [g f]
2) Is there a way of doing a 'mostly random' ordering where, say you had a list such as:
64 69 72 72
64 72 69 75
76 67 72 70
62 69 65 72
71 74 65 77
74 69 65 72
67 71 74 74
67 76 72 79
76 79 71 82
60 64 69 67
64 67 72 70
67 64 60 67
72 65 69 68
74 71 65 74
65 69 62 72
71 74 67 77
71 62 65 65
67 72 64 75
77 74 71 77
76 72 67 75
77 69 74 72
74 67 71 70
79 71 74 74
76 71 79 74
69 62 65 65
65 62 71 65
69 65 74 68
69 64 60 67
71 79 74 82
71 74 77 77
69 74 77 77
72 69 77 72
77 72 69 75
74 65 71 68
71 62 67 65
71 77 74 80
74 77 71 80
77 71 74 74
69 65 72 68
65 71 74 74
67 71 76 74
64 67 60 70
65 72 69 75
71 74 79 77
72 76 69 79
67 62 71 65
72 69 65 72
69 72 76 75
79 74 71 77
72 67 64 70
71 67 76 70
67 72 76 75
71 65 74 68
65 69 60 72
69 72 77 75
64 69 60 72
76 69 72 72
69 76 72 79
64 72 67 75
72 77 69 80
67 76 71 79
69 60 65 63
67 60 64 63
71 64 67 67
69 60 64 63
71 67 62 70
60 64 67 67
74 69 77 72
65 74 71 77
62 71 65 74
67 71 64 74
65 74 69 77
76 67 71 70
62 67 71 70
74 71 79 74
77 74 69 77
67 64 71 67
62 65 71 68
65 60 69 63
62 65 69 68
60 69 65 72
71 65 62 68
65 69 74 72
67 74 71 77
71 79 76 82
69 74 65 77
69 77 72 80
67 71 62 74
72 64 67 67
74 77 69 80
76 72 69 75
69 72 65 75
71 76 79 79
64 60 67 63
64 60 69 63
74 65 69 68
79 76 71 79
64 67 71 70
72 67 76 70
72 76 67 79
69 65 60 68
60 67 64 70
69 64 72 67
69 65 62 68
65 62 69 65
74 71 67 74
65 69 72 72
72 69 64 72
60 69 64 72
76 71 67 74
64 71 67 74
60 65 69 68
74 79 71 82
65 71 62 74
67 64 72 67
71 67 74 70
79 71 76 74
62 71 67 74
74 71 77 74
71 67 64 70
72 64 69 67
71 76 67 79
69 77 74 80
77 69 72 72
69 72 64 75
72 69 76 72
you could order this so that the row order is random but that all of the numbers in the first column are mostly close to each other by a defined parameter (for example 62 might be followed by 67 or 58 but wouldn't be followed by say 80)? (To make things even more complicated might there be a way of specifying that this take place most but not all of the time?)
3) What's a concise way of creating a column vector that goes
0
0
0
0
1
1
1
1
2
2
2
2
3
3
3
3
etc, up until a specified length (or, failing that, up until a specified number)?
For 1) You can use this code:
%sprows is just a utility function, which splits a matrix into a cell
sprows=#(x)(mat2cell(x,ones(size(x,1),1)))
%get all combinations of perms(a) and a
cell2mat(allcomb(sprows(perms(a)),sprows(a(:))))
It uses allcomb from matlab file exchange, available here
3):
x=repmat(0:3,4,1);
x=x(:);
As you were told in the comments, your question 2 is not defined enough. It probably deserve a question on its own, with the constraints better detailed and explained.
That said, another alternative for 1) and 2):
so many ways to do that
Q1:
long way
a = [1 2 3] ; %// starting set
n = numel(a) ;
lastCol = ones(factorial(n),1) * a ;
ap = [repmat(perms(a),n,1) lastCol(:)] ;
or directly without intermediate variable:
ap = [repmat(perms(a),numel(a),1) reshape(ones(factorial(numel(a)),1)*a,[],1)] ;
Q3:
Same method than used above. A matrix multiplication reshaped into a colum vector:
n = 3 %// your specified number
v = 0:n ;
Vlong = reshape(ones(numel(v),1)*v,[],1) ;