-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfunDef.txt
2022 lines (2020 loc) · 168 KB
/
funDef.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% This is the function definition master file. It is used for reading from the MATL compiler, and for generating LaTeX content.
% Comment lines start with "%" symbol
% Columns are separated by tabs, and are as follows:
% - source: MATL source code
% - minIn: minimum number of inputs. This is interpreted as a string that goes to the compiled code directly
% - maxIn: default number of inputs. A string too
% - defIn: default number of inputs
% - altIn: alternative number of inputs
% - minOut: minimum number of outputs
% - maxOut: maximum number of outputs
% - defOut: default number of outputs. A string too
% - altOut: alternative number of outputs
% - consumeInputs: whether used inputs are removed from the stack
% - wrap: whether function body should be wrapped at all
% - funInClipboard: whether function inputs should overwrite clipboard
% - allowedOnline: whether function is allowed in the online compiler
% - body: function body. May span several lines, leaving first column empty
% - comment (for matl program)
% - description (for LaTeX)
%
% src minIn maxIn defIn altIn minOut maxOut defOut altOut consumeInputs wrap funInClipboard allowedOnline body Comment (for matl) description (for LaTex)
! 1 2 1 2 1 1 1 true true true true if numel(in)==1, if ndims(in{1})==2, out{1} = in{1}.'; else, out{1} = permute(in{1}, [2 1 3:ndims(in{1})]); end transpose / permute array dimensions If $1$ input: \matlab+.'+ (\matlab+transpose+), or \matlab+permute(..., [2 1 ...])+ for multidimensional arrrays. If $2$ inputs: \matlab+permute+. If the second input is 1, 2 or 3 it indicates which dimension is not permuted for a 3D array; that is, it corresponds to [1 3 2], [3 2 1] or [2 1 3] respectively
else
if isequal(in{2}, 1), in{2} = [1 3 2]; elseif isequal(in{2}, 2), in{2} = [3 2 1]; elseif isequal(in{2}, 3), in{2} = [2 1 3]; end
out{1} = permute(in{:});
end
X! 1 2 2 1 1 1 true true true true out{1} = rot90(in{:}); rotate array in steps of 90 degrees \matlab+rot90+
Y! 1 1 1 0 2 2 true true true false [out{:}] = system(in{:}); execute system command \matlab+system+
Z! 1 1 1 1 1 1 true true true true out{1} = full(in{1}); convert sparse matrix to full matrix \matlab+full+
"
X" 2 inf 3 1 1 1 true true true true out{1} = repmat(in{:}); replicate and tile array \matlab+repmat+
Y" 2 inf 2 3 1 1 1 true true true true if numel(in)==2 && ~isvector(in{2}), in{2} = in{2}(:); end replicate elements of array \matlab+repelem+ (run-length decoding). With $2$ inputs: if the first or second inputs are empty the output is empty. Else, the second input is linearized if needed; and if the first or second input is shorter than the other, entries are repeated cyclically to match lengths
if isempty(in{1}) || isempty(in{2})
out{1} = in{1}([]);
else
if numel(in)==2 && ~isscalar(in{2}) && numel(in{1}) < numel(in{2}), in{1} = in{1}(mod(0:numel(in{2})-1, numel(in{1}))+1); end
if numel(in)==2 && ~isscalar(in{1}) && numel(in{2}) < numel(in{1}), in{2} = in{2}(mod(0:numel(in{1})-1, numel(in{2}))+1); end
out{1} = repelem(in{:});
end
Z" 1 1 1 1 1 1 true true true true S = ' '; string or array of blanks \matlab+blanks+. It allows vector input, and in that case it produces a matrix or multidimensional array
if numel(in{1})<=1, y = S(ones(1,in{1}));
else, y = S(ones(in{1}));
end
out{1} = y; clear S
#
X# 0 0 0 0 0 0 false false false true disp('/-------'), celldisp(STACK), disp('-------/') display stack contents display stack as a cell array
Y# 2 inf 2 3 0 0 0 true true true true if numel(in)==2 sound / soundsc / audiowrite (i) With $2$ inputs: \matlab+sound+. If second input is \matl+T+, it is interpreted as \matl+44100+. If second input is \matl+F+, it is interpreted as \matl+44100+ and \matlab+audiowrite+ is called instead of \matlab+sound+, with file name \matlab+'audio.wav'+. (ii) With $3$ inputs: if third input is a truthy scalar, \matlab+soundsc+ is called with the first two inputs. If third input is a numeric vector of size $2$, \matlab+soundsc+ is called with the three inputs. In both cases, \matl+T+ in second input is interpreted as \matl+44100+. If third input is a string, it defines a file name, and \matlab+audiowrite+ is called with that file name and the other two inputs. (iii) With more than $3$ inputs: \matlab+audiowrite+ is called using the third input as file name. Further inputs specify parameter-value pairs. \matl+T+ in second input is interpreted as \matl+44100+.
if islogical(in{2})&&isscalar(in{2})&&in{2}
sound(in{1},44100)
elseif islogical(in{2})&&isscalar(in{2})&&~in{2}
audiowrite('audio.wav',in{1},44100);
else
sound(in{:})
end
elseif numel(in)==3
if islogical(in{2})&&isscalar(in{2})&&in{2}, in{2} = 44100; end
if isscalar(in{3})&&in{3}
soundsc(in{1},in{2})
elseif isnumeric(in{3})&&numel(in{3})==2
soundsc(in{:})
elseif ischar(in{3})
audiowrite(in{3},in{1},in{2})
else
error('MATL:runtime', 'MATL run-time error: input not allowed');
end
else
if islogical(in{2})&&isscalar(in{2})&&in{2}, in{2} = 44100; end
audiowrite(in{3},in{1},in{2},in{4:end})
end
Z# 1 3 1 2 0 0 0 true true true false data = in{1}; if ~iscell(data), data = {data}; end write to file Writes first input to file \comp{inout}, creating it if necessary. If the file exists, by default its previous contents are overwritten. If the input is a numeric or char array each entry is treated as a raw byte and written. Behaviour is undefined for entries exceeding $255$. If the input is a cell array, the contents of each cell are written, with a byte $10$ (representing newline) in between. With $2$ inputs: second input specifies file name; it is converted to char is necessary; if empty defaults to \comp{inout}. With $3$ inputs: third input specifies whether previous contents of the file should be kept
sep = 10;
if numel(in)>=2 && ~isempty(in{2}), file = in{2}; else file = 'inout'; end
if numel(in)>=3 && in{3}, perm = 'a'; else perm = 'w'; end
if ~ischar(file), file = char(file); end
fid = fopen(file, perm);
for n = 1:numel(data)
fwrite(fid, data{n});
if n<numel(data), fwrite(fid, sep); end
end
fclose(fid); clear file sep
$
X$ 1 1 1 1 1 1 true true true true if ~ischar(in{1}), out{1} = sym(in{1}); else out{1} = str2sym(in{1}); end convert to symbolic (i) For non-char input: \matlab+sym+. (ii) For char input: \matlab+str2sym+. \sa \matl+Y$+
Y$ 2 2 2 1 1 1 true true true true if in{2}>0 variable precision arithmetic (i) \matlab+char(vpa(str2sym(...), ...))+ for char input, or \matlab+char(vpa(...))+ for non-char input. Second input is number of significant digits. (ii) If the first input is a number or a string representing a real or imaginary scalar and the second input (number of significant digits) is negative, the latter is interpreted as its absolute value, and the output will give the actual digits without rounding (so inputs \matlab+'5/3'+ and \matlab+-4+ will produce \matlab+'1.666'+, not \matlab+'1.667'+). \sa \matl+X$+
if ~ischar(in{1}), out{1} = char(vpa(in{:})); else out{1} = char(vpa(str2sym(in{1}), in{2:end})); end
elseif in{2}<0
s = in{1}; W = -in{2};
E = 0;
done = false;
while ~done
E = E+1;
if ~ischar(s), x = char(vpa(s, W+E)); else x = char(vpa(str2sym(s), W+E)); end
y = regexprep(x, '^[+-]?0*|\.0*', '');
y = regexprep(y, '\D.*$', '');
num_digits = numel(y); % get number of significant digits in x:
done = num_digits==W+E && x(end)~='0';
end
c = find(~ismember(x, ['0':'9' '+-.']), 1);
if c
z = [x(1:c-1-E) x(c:end)];
else
z = x(1:end-E);
end
out{1} = z;
clear s W E done x y num_digits c z
else error('MATL:runtime', 'MATL run-time error: input not allowed');
end
% https://stackoverflow.com/questions/49649503/obtain-first-significant-digits-of-a-number-using-variable-precision-arithmetic
Z$ 0 1 0 1 1 1 1 true true true false if ~numel(in) || isempty(in{1}), in{1} = 'inout'; end; fid = fopen(in{1}, 'r'); read from file Reads bytes from specifed file. Each individual byte is then converted to a char, and the output is a row vector of char. If $0$ inputs or empty input: file name is \comp{inout}.
x = reshape(char(fread(fid,inf,'*uint8')),1,[]);
fclose(fid); out{1} = x;
%
X% 1 1 1 1 1 1 true true true true out{1} = class(in{1}); class class of input (\matlab+class+ with one input)
Y% 2 3 2 1 1 1 true true true true str = {'uint8' 'int8' 'uint64' 'int64' 'uint16' 'int16' 'uint32' 'int32' 'double' 'single'}; cast to data type \matlab+cast+. This function allows strings in second input to be replaced by numbers, as follows: 1: \matlab+'uint8'+, 2: \matlab+'int8'+, 3: \matlab+'uint64'+, 4: \matlab+'int64'+, 5: \matlab+'uint16'+, 6: \matlab+'int16'+, 7: \matlab+'uint32'+, 8: \matlab+'int32'+, 9: \matlab+'double'+, 10: \matlab+'single'+
if isnumeric(in{2}), in(2) = str(in{2}); end; clear str
out{1} = cast(in{:});
Z% 2 2 2 1 1 1 true true true true str = {'uint8' 'int8' 'uint64' 'int64' 'uint16' 'int16' 'uint32' 'int32' 'double' 'single'}; convert datatypes without changing underlying data \matlab+typecast+. This function allows strings in second input to be replaced by numbers, as follows: 1: \matlab+'uint8'+, 2: \matlab+'int8'+, 3: \matlab+'uint64'+, 4: \matlab+'int64'+, 5: \matlab+'uint16'+, 6: \matlab+'int16'+, 7: \matlab+'uint32'+, 8: \matlab+'int32'+, 9: \matlab+'double'+, 10: \matlab+'single'+
if isnumeric(in{2}), in(2) = str(in{2}); end; clear str
out{1} = typecast(in{:});
&
X& 2 4 2 3 1 3 1 true true true true str = {'rows' 'stable' 'sorted'}; set intersection \matlab+intersect+. Uses the \matlab+'stable'+ flag by default. If one input is char and the other is numeric, the latter is converted to char. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'rows'+, 2: \matlab+'stable'+, 3: \matlab+'sorted'+
for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str
if ischar(in{1}) && isnumeric(in{2}), in{2} = char(in{2}); end
if ischar(in{2}) && isnumeric(in{1}), in{1} = char(in{1}); end
if numel(in)==2 || (numel(in)==3 && strcmp(in{3},'rows')), in{end+1}='stable'; end, [out{:}] = intersect(in{:});
Y& 0 inf 2 numel(STACK) 1 1 1 true true true true if isempty(in), y = true; else y = in{1}; for n=2:numel(in), if ~isa(y,'sym')&&~isa(in{n},'sym') y = bsxfun(@and, y, in{n}); else y = y & in{n}; end; end; end; if numel(in)==1, y = logical(y); end; out{1} = y; clear y n; logical 'and' (element-wise, singleton expansion) \matlab+&+ (\matlab+and+), element-wise with singleton expansion
% MATL didn't initially support symbolic data; and bsxfun was used rather than implicit expansion. When introducing symbolic support I noticed that MATLAB doesn't allow bsxfun for symbolic, but it allows the normal operation with implicit expantion; Octave allows bsxfun or the normal operation but without expansion. So, to make it work in MATLAB without spoiling it in Octave, I change bsxfun to normal operation; but only for symbolic, because I don't want to change the code for non-symbolic inputs
Z& 2 3 2 1 1 1 true true true true if ischar(in{1}), in{1} = double(in{1}); end; if ischar(in{2}), in{2} = double(in{2}); end bit-wise logical 'and' (element-wise, singleton expansion) \matlab+bitand+ (bitwise 'and'), element-wise with singleton expansion. If first or second inputs are \matlab+char+ they are converted to \matlab+double+. \matlab+double+ inputs are rounded. If the inputs are \matlab+double+ they can have negative values, and in that case they must be in the range from \matlab+-2^52+ up to \matlab+2^52-1+. \sa \matl+Z|+, \matl+Z~+
in{1} = round(in{1}); in{2} = round(in{2});
if any(in{1}(:)<0) || any(in{2}(:)<0), neg = true; else neg = false; end
if neg, in{1} = mod(in{1}, 2^53); in{2} = mod(in{2}, 2^53); end;
if max(size(in{1}))==1 || max(size(in{2}))==1 || isequal(size(in{1}), size(in{2}))
out{1} = bitand(in{:});
else
nd = max(ndims(in{1}), ndims(in{2})); sz1 = arrayfun(@(n)size(in{1},n), 1:nd); sz2 = arrayfun(@(n)size(in{2},n), 1:nd);
assert(all(sz1==sz2 | sz1==1 | sz2==1), 'MATL:runtime', 'MATL run-time error: inputs have incompatible sizes')
rm1 = ones(1,nd); rm1(sz1==1) = sz2(sz1==1); rm2 = ones(1,nd); rm2(sz2==1) = sz1(sz2==1);
insx1 = repmat(in{1}, rm1); insx2 = repmat(in{2}, rm2); out{1} = bitand(insx1, insx2, in{3:end});
clear nd sz1 sz2 rm1 rm2 insx1 insx2
end
if neg, out{1} = mod(out{1} - 2^52, 2^53) - 2^52; end; clear neg
'
X' 1 inf 2 2 0 inf 1 true true true false [out{:}] = feval(in{end}, in{1:end-1}); execute Matlab function execute Matlab function specified by last input, using the rest of the inputs as arguments.
Y' 1 1 1 2 2 2 [false true] true true true true data = in{1}(:); run-length encoding run-length encoding (inverse of \matlab+repelem+). Input may be an array or cell array. Numeric values must be finite
if isempty(in{1}), if iscell(in{1}), out={{} []}; else, out={[] []}; end;
else
if ~iscell(in{1}), ch = [1; find(diff(data))+1; numel(data)+1];
else ch = 1; for n=2:numel(data), if ~isequal(data{n-1},data{n}), ch = [ch; n]; end; end; ch = [ch; numel(data)+1]; end
result = {data(ch(1:end-1)), diff(ch)};
if ndims(in{1})==2 && size(in{1},1)==1, result{1} = result{1}.'; result{2} = result{2}.'; end
[out{:}] = result{:};
end
Z' 0 1 0 1 1 1 1 true true true true if numel(in)==0, out{1} = now; current date and time \matlab+now+. With $1$ input: the input should be numeric with values from 1 to 6, which are used as indices into the output of \matlab+clock+
elseif numel(in)==1, c = clock; out{1} = c(in{1});
else error('MATL:runtime', 'MATL run-time error: too many inputs'); end
( 3 inf 3 4 1 1 1 true true true true if numel(in)==3 && iscell(in{3}) assignment ( ) indexing assignment \matlab+( )+ indexing. Null assignment (\matlab+x(...) = []+) can only be done with a single index. \sa \matl+Y(+, \matl+Z(+
arrayDestination = in{1};
arrayData = in{2};
indices = in{3};
Ni = numel(indices);
numelmax = max(cellfun(@numel, indices));
for n = 1:Ni
if isscalar(indices{n}), indices{n} = repmat(indices{n},1,numelmax); else indices{n} = reshape(indices{n},1,[]); end
end; clear numelmax
indmat = vertcat(indices{:});
for k = 1:size(indmat,2)
indcol = indmat(:,k);
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
indcol = round(indcol);
nonpos = indcol<=0;
indcol(nonpos) = mod(indcol(nonpos).'-1,sz(nonpos))+1;
indcol = num2cell(indcol);
if ~isempty(arrayData), arrayDestination(indcol{:}) = arrayData((k-1)*(numel(arrayData)>1)+1);
else arrayDestination(indcol{:}) = [];
end
end
out{1} = arrayDestination;
clear arrayDestination arrayData indices indmat indcol nonpos Ni sz n k
% Above is for "element-wise" indexing; below is "normal"
else
arrayDestination = in{1};
arrayData = in{2};
indices = in(3:end);
Ni = numel(indices);
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = round(indices{n});
ind = indices{n}<=0;
indices{n}(ind) = mod(indices{n}(ind)-1,sz(n))+1;
end; clear ind
end
if ~isempty(arrayData), arrayDestination(indices{:}) = arrayData;
else arrayDestination(indices{:}) = [];
end
out{1} = arrayDestination;
clear arrayDestination arrayData indices Ni sz n
end
% This code above was easy, after the code for ) had been done
% shiftdim is needed to preserve end-index shape (the colon operation gives a row vector both for say [1 0] and [1;0]). I realized this here, with assignment indexing. For referencing indexing and for curly-brace indexing it probably doesn't matter, but I also add the shiftdim operation there just in case
% `data = []; x=[5 4 7]; x([1 3]) = data;` doesn't work. It has to be `data = []; x=[5 4 7]; x([1 3]) = [];`. In addition, for indexing with various indices, all of them except for one should be `:`. But MATL doesn't have `:`. So assignment with [] only works with one index.
X( 3 inf 3 1 1 1 true true true true assert(iscell(in{1}), 'MATL:runtime', 'MATL run-time error: a cell array is needed as first input') assignment {} indexing assignment \matlab+{ }+ indexing
if numel(in)==3, in{4} = 1; end; Ni = in{end};
if in{end}==1 && iscell(in{end-1})
indices = in{end-1};
Ni = numel(indices);
data = in(2:end-2);
arrayDestination = in{1};
numelmax = max(cellfun(@numel, indices));
for n = 1:Ni
if isscalar(indices{n}), indices{n} = repmat(indices{n},1,numelmax); else indices{n} = reshape(indices{n},1,[]); end
end; clear numelmax
indmat = vertcat(indices{:});
for k = 1:size(indmat,2)
indcol = indmat(:,k);
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
indcol = round(indcol);
nonpos = indcol<=0;
indcol(nonpos) = mod(indcol(nonpos).'-1,sz(nonpos))+1;
indcol = num2cell(indcol);
arrayDestination(indcol{:}) = data((k-1)*(numel(data)>1)+1);
end
out{1} = arrayDestination;
clear arrayDestination data indices indmat indcol nonpos Ni sz n k
% Above is for "element-wise" indexing; below is "normal"
else
Ni = in{end};
indices = in(end-Ni:end-1);
data = in(2:end-Ni-1);
arrayDestination = in{1};
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = round(indices{n});
ind = indices{n}<=0;
indices{n}(ind) = mod(indices{n}(ind)-1,sz(n))+1;
end; clear ind
end
nei = cellfun(@nnz, indices);
if numel(nei)==1, nei = [nei 1]; end
arrayDestination(indices{:}) = reshape(data, nei);
out{1} = arrayDestination;
clear arrayDestination data indices Ni sz n
end
% This code above was based on that for (.
% An added difficulty is that `[arrayDestination{indices{:}}] = deal(data{:})` doesn't work (but explicitly writing the indices does work!: [arrayDestination{1:2, 3:4}] = deal(data{:}) ). So I had to use () indexing on the LHS and reshape on the RHS
% nnz works for numeric, logical or char indices
Y( 2 inf 3 1 1 1 true true true true arrayDestination = in{1}; assignment ( ) indexing with final colon assignment \matlab+(..., :)+ indexing. Null assignment (\matlab+x(..., :) = []+) can only be done with a single index (in addition to the implicit colon). \sa \matl+(+, \matl+Z(+
arrayData = in{2};
indices = [in(3:end) {':'}];
Ni = numel(indices);
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = round(indices{n});
ind = indices{n}<=0;
indices{n}(ind) = mod(indices{n}(ind)-1,sz(n))+1;
end; clear ind
end
if ~isempty(arrayData), arrayDestination(indices{:}) = arrayData;
else arrayDestination(indices{:}) = [];
end
out{1} = arrayDestination;
% The code for Y( is the same as it was for ( before introducing element-wise indexing, except for the `indices = ...` line
Z( 2 inf 3 1 1 1 true true true true arrayDestination = in{1}; assignment ( ) indexing with initial colon assignment \matlab+(:, ...)+ indexing. Null assignment (\matlab+x(:, ...) = []+) can only be done with a single index (in addition to the implicit colon). \sa \matl+(+, \matl+Y(+
arrayData = in{2};
indices = [{':'} in(3:end)];
Ni = numel(indices);
sz = size(arrayDestination);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = round(indices{n});
ind = indices{n}<=0;
indices{n}(ind) = mod(indices{n}(ind)-1,sz(n))+1;
end; clear ind
end
if ~isempty(arrayData), arrayDestination(indices{:}) = arrayData;
else arrayDestination(indices{:}) = [];
end
out{1} = arrayDestination;
% The code for Z( is the same as it was for ( before introducing element-wise indexing, except for the `indices = ...` line
) 2 inf 2 1 2 1 2 true true true true if numel(in)==2 && iscell(in{2}) reference ( ) indexing / split array reference \matlab+( )+ indexing. If $2$ outputs: only one input index can be used. The second output produces the "complementary" array \matlab+y=x; y(ind)=[]+, where \matlab+x+ and \matlab+ind+ are the inputs. \sa \matl+Y)+, \matl+Z)+
array = in{1};
indices = in{2};
Ni = numel(indices);
[~,nmax] = max(cellfun(@numel, indices));
for n = [1:nmax-1 nmax+1:Ni]
if isscalar(indices{n}), indices{n} = repmat(indices{n}, size(indices{nmax})); else indices{n} = reshape(indices{n}, size(indices{nmax})); end
end; clear nmax
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
if numel(sz)==1, sz = [sz 1]; end
for n = 1:Ni, indices{n} = mod(round(indices{n})-1,sz(n))+1; end
indices = {sub2ind(sz, indices{:})};
% Above is for "element-wise" indexing; below is "normal"
else
array = in{1};
indices = in(2:end);
Ni = numel(indices);
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = mod(round(indices{n})-1,sz(n))+1;
end
end
end
out{1} = array(indices{:});
if nout>1, y = array; if ~isvector(y), y = y(:).'; end; y(indices{:}) = []; out{2} = y; end
clear indices array Ni sz n
% This code above for ) indexing has been a little difficult. It had to correctly handle an arbitrary number of indices, possibly with partially linear indexing; and end-based indexing. Then I added modular indexing (for scalar indices). / Then I changed end-based indexing, which allowed me to modular indexing not only for scalar indices. Then came element-wise indexing
% Indexing can be done with chars, but then modulo and rounding are not applied (hence `if ~islogical(indices{n}) && ~ischar(indices{n})` and not just `if ~islogical(indices{n})`). This is because `':'` used as an index has a special meaning in Matlab, and also in MATL
% That `isvector` above is needed because `y = [1 3 5; 2 4 6]; y([1 3 5]) = []` gives `[2 4 6]` in Matlab but `[2; 4; 6]` in Octave (4.0.0). The pattern seems to be: if ~isvector(y), Matlab reshapes as a row, whereas Octave reshapes as a column
X) 2 inf 2 0 inf -1 true true true true assert(iscell(in{1}), 'MATL:runtime', 'MATL run-time error: a cell array is needed as first input') reference {} indexing reference \matlab+{ }+ indexing
if numel(in)==2 && iscell(in{2})
array = in{1};
indices = in{2};
Ni = numel(indices);
[~,nmax] = max(cellfun(@numel, indices));
for n = [1:nmax-1 nmax+1:Ni]
if isscalar(indices{n}), indices{n} = repmat(indices{n}, size(indices{nmax})); else indices{n} = reshape(indices{n}, size(indices{nmax})); end
end; clear nmax
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
if numel(sz)==1, sz = [sz 1]; end
for n = 1:Ni, indices{n} = mod(round(indices{n})-1,sz(n))+1; end
indices = {sub2ind(sz, indices{:})};
% Above is for "element-wise" indexing; below is "normal"
else
array = in{1};
assert(iscell(array), 'MATL:runtime', 'MATL run-time error: a cell array is needed as first input')
indices = in(2:end);
Ni = numel(indices);
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = mod(round(indices{n})-1,sz(n))+1;
end
end
end
out = reshape(array(indices{:}),1,[]);
if nout>=0, out = out(1:nout); end
clear indices array Ni sz n
Y) 1 inf 2 1 2 1 2 true true true true array = in{1}; reference ( ) indexing with final colon reference \matlab+(..., :)+ indexing. If $2$ outputs: only one input index can be used. The second output produces the "complementary" array \matlab+y=x; y(ind,:)=[]+, where \matlab+x+ and \matlab+ind+ are the inputs. \sa \matl+)+, \matl+Z)+
indices = [in(2:end) {':'}];
Ni = numel(indices);
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = mod(round(indices{n})-1,sz(n))+1;
end
end
out{1} = array(indices{:});
if nout>1, y = array; y(indices{:}) = []; out{2} = y; end
% Y) is the same as ) was before introducing element-wise indexing, except for the `indices = ...` line
Z) 1 inf 2 1 2 1 2 true true true true array = in{1}; reference ( ) indexing with initial colon reference \matlab+(:, ...)+ indexing. If $2$ outputs: only one input index can be used. The second output produces the "complementary" array \matlab+y=x; y(:,ind)=[]+, where \matlab+x+ and \matlab+ind+ are the inputs. \sa \matl+)+, \matl+Y)+
indices = [{':'} in(2:end)];
Ni = numel(indices);
sz = size(array);
if Ni<numel(sz), sz = [ sz(1:Ni-1) prod(sz(Ni:end)) ]; elseif Ni>numel(sz), sz = [ sz ones(1,Ni-numel(sz)) ]; end
for n = 1:Ni
if ~islogical(indices{n}) && any(imag(indices{n}(:)))
indices{n} = num2cell(real(indices{n})+sz(n)*imag(indices{n}));
if numel(indices{n})==1, indices{n} = indices{n}{1}; else shape = find(size(indices{n})>1,1); indices{n} = colon(indices{n}{:}); indices{n} = shiftdim(indices{n}(:),1-shape); end
end
if ~islogical(indices{n}) && ~ischar(indices{n})
indices{n} = mod(round(indices{n})-1,sz(n))+1;
end
end
out{1} = array(indices{:});
if nout>1, y = array; y(indices{:}) = []; out{2} = y; end
% Z) is the same as ) was before introducing element-wise indexing, except for the `indices = ...` line
* 1 inf 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end array product (element-wise, singleton expansion) \matlab+.*+ (\matlab+times+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
y = in{1}; for n=2:numel(in), if ~isa(y,'sym')&&~isa(in{n},'sym') y = bsxfun(@times, y, in{n}); else y = y .* in{n}; end; end;
out{1} = y; clear y n;
X* 2 2 2 1 1 1 true true true true out{1} = kron(double(in{1}), double(in{2})); Kronecker tensor product \matlab+kron+
Y* 2 2 2 1 1 1 true true true true if islogical(in{1}), in{1} = double(in{1}); end matrix product matrix product, \matlab+*+ (\matlab+mtimes+)
if islogical(in{2}), in{2} = double(in{2}); end
out{1} = in{1}*in{2};
Z* 1 inf 2 numel(STACK) 1 1 1 true true true true n = numel(in); combs = cell(1,n); Cartesian product Cartesian product. Given a number $n$ of arrays of possibly different sizes, generates an $n$-column matrix whose rows describe all combinations of elements taken from those arrays
[combs{end:-1:1}] = ndgrid(in{end:-1:1});
combs = cat(n+1, combs{:}); combs = reshape(combs,[],n);
out{1} = combs; clear combs n
+ 1 inf 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end addition (element-wise, singleton expansion) \matlab|+| (\matlab+plus+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
y = in{1}; for n=2:numel(in), if ~isa(y,'sym')&&~isa(in{n},'sym') y = bsxfun(@plus, y, in{n}); else y = y + in{n}; end; end;
out{1} = y; clear y n;
X+
Y+ 2 3 2 3 1 1 1 true true true true str = {'same' 'valid' 'full'}; two-dimensional convolution \matlab+conv2+. Doesn't allow two-vector and one matrix mode. Converts first two inputs to \matlab+double+. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'same'+, 2: \matlab+'valid'+, 3: \matlab+'full'+. \sa \matl|Z+|
for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str
if issparse(in{1}), in{1} = full(in{1}); end; if issparse(in{2}), in{2} = full(in{2}); end
out{1} = conv2(double(in{1}), double(in{2}), in{3:end});
Z+ 2 3 2 3 1 1 1 true true true true if issparse(in{1}), in{1} = full(in{1}); end; if issparse(in{2}), in{2} = full(in{2}); end two-dimensional convolution maintaining size / circular convolution (i) If $2$ inputs: \matlab+conv2(..., 'same')+. (ii) If $3$ inputs: \matlab+cconv+. Non-vector inputs are linearized into column vectors. The output is of type \matlab+double+. Integer inputs are guaranteed to give exact integer results, up to \matlab+double+ data type limitations. (i,ii) Inputs are converted to \matlab+double+. \sa \matl|Y+|
if numel(in)==2
out{1} = conv2(double(in{1}), double(in{2}), 'same');
else
if ~isvector(in{1}), in{1} = in{1}(:); end
if ~isvector(in{2}), in{2} = in{2}(:); end
if ~isnumeric(in{1}), in{1} = double(in{1}); end
if ~isnumeric(in{2}), in{2} = double(in{2}); end
y = cconv(double(in{1}), double(in{2}), double(in{3}));
if all(mod(in{1},1)==0) && all(mod(in{2},1)==0), y = round(y); end
out{1} = y; clear y
end
,
X, 1 1 1 1 1 1 true true true true out{1} = cos(in{1}); cosine (radians) \matlab+cos+
Y, 1 1 1 1 1 1 true true true true out{1} = sin(in{1}); sine (radians) \matlab+sin+
Z, 1 1 1 1 1 1 true true true true out{1} = tan(in{1}); tangent (radians) \matlab+tan+
- 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end subtraction (element-wise, singleton expansion) \matlab+-+ (\matlab+minus+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@minus, in{1}, in{2}); else out{1} = in{1} - in{2}; end
X- 2 4 2 3 1 2 1 true true true true str = {'rows' 'stable' 'sorted'}; set difference \matlab+setdiff+. Uses the \matlab+'stable'+ flag by default. If one input is char and the other is numeric, the latter is converted to char. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'rows'+, 2: \matlab+'stable'+, 3: \matlab+'sorted'+. \sa \matl+X~+
for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str
if ischar(in{1}) && isnumeric(in{2}), in{2} = char(in{2}); end
if ischar(in{2}) && isnumeric(in{1}), in{1} = char(in{1}); end
if numel(in)==2, in{3}='stable'; end, [out{:}] = setdiff(in{:});
Y- 2 2 2 1 2 1 2 true true true true [out{:}] = deconv(in{:}); deconvolution and polynomial division \matlab+deconv+
Z-
.
X.
Y. 0 1 1 0 0 0 true true true true pause(in{:}) pause \matlab+pause+ (without outputs)
Z. 2 3 2 1 1 1 true true true true if ischar(in{1}), in{1} = double(in{1}); end get bit \matlab+bitget+. If first input is \matlab+char+ it is automatically converted to \matlab+double+
out{1} = bitget(in{:});
/ 2 2 2 1 1 1 true true true true if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@rdivide, in{1}, in{2}); else out{1} = in{1} ./ in{2}; end array right division (element-wise, singleton expansion) \matlab+./+ (\matlab+rdivide+), element-wise with singleton expansion
X/ 1 1 1 1 1 1 true true true true out{1} = angle(in{1}); phase angle (radians) \matlab+angle+
Y/ 2 2 2 1 1 1 true true true true out{1} = in{1}/in{2}; right matrix division right matrix division, \matlab+/+ (\matlab+mrdivide+)
Z/ 1 3 1 1 1 1 true true true true out{1} = unwrap(in{:}); unwrap phase angle \matlab+unwrap+
0
X0 1 1 1 1 1 1 true true true true fn = 'X0'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y0 1 1 1 1 1 1 true true true true fn = 'Y0'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z0
1
X1 1 1 1 1 1 1 true true true true fn = 'X1'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y1 1 1 1 1 1 1 true true true true fn = 'Y1'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z1
2
X2 1 1 1 1 1 1 true true true true fn = 'X2'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y2 1 1 1 1 1 1 true true true true fn = 'Y2'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z2
3
X3 1 1 1 1 1 1 true true true true fn = 'X3'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y3 1 1 1 1 1 1 true true true true fn = 'Y3'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z3
4
X4 1 1 1 1 1 1 true true true true fn = 'X4'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y4 1 1 1 1 1 1 true true true true fn = 'Y4'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z4
5
X5 1 1 1 1 1 1 true true true true fn = 'X5'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y5 1 1 1 1 1 1 true true true true fn = 'Y5'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z5
6
X6 1 1 1 1 1 1 true true true true fn = 'X6'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y6 1 1 1 1 1 1 true true true true fn = 'Y6'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Z6
7
X7 1 1 1 1 1 1 true true true true fn = 'X7'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y7
Z7
8
X8 1 1 1 1 1 1 true true true true fn = 'X8'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y8
Z8
9
X9 1 1 1 1 1 1 true true true true fn = 'X9'; k = find(preLit.(fn).key==in{1}, 1); predefined literals predefined literal depending on input
assert(~isempty(k), 'MATL:runtime', 'MATL run-time error: input not allowed in function %s', fn);
out{1} = preLit.(fn).val{k};
Y9
Z9
: 1 3 1 2 1 1 1 true true true true if numel(in)==1 && iscell(in{1}), in = in{1}; end range; vector of equally spaced values \matlab+colon+ (with three inputs \matlab+x+, \matlab+y+, \matlab+z+ produces \matlab+x:y:z+; with two inputs \matlab+x+, \matlab+y+ produces \matlab+x:y+). If one input: produces \matlab+1:x+, or \matlab+' ':x+ if \matlab+x+ is char. For a single cell-array input, the contents of the cell array are interpreted as the actual inputs.
if numel(in)==1
if ischar(in{1}), s = ' '; else s = 1; end
out{1} = colon(s,in{:}); clear s
else
out{1} = colon(in{:}); end
X: 1 1 1 1 1 1 true true true true out{1} = in{1}(:); linearize to column array linearize to column array (index with \matlab+(:)+)
Y: 1 1 1 0 inf numel(in{1}) true true true true assert(iscell(in{1}), 'MATL:runtime', 'MATL run-time error: a cell array is needed as input'); unbox cell array generate comma-separated list from cell array (index with \matlab+{:}+) and push each element onto stack
out = reshape(in{1}(1:nout),1,[]);
Z: 2 4 3 1 1 1 true true true true if ischar(in{1}), in{1} = double(in{1}); end set bit \matlab+bitset+. If first input is \matlab+char+ it is automatically converted to \matlab+double+
out{1} = bitset(in{:});
;
X; 1 1 1 1 1 1 true true true true out{1} = acos(in{1}); inverse cosine (radians) \matlab+acos+
Y; 1 1 1 1 1 1 true true true true out{1} = asin(in{1}); inverse sine (radians) \matlab+asin+
Z; 2 2 2 1 1 1 true true true true if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@atan2, in{1}, in{2}); else out{1} = atan2(in{1}, in{2}); end four quadrant inverse tangent (radians; element-wise, singleton expansion) \matlab+atan2+, element-wise with singleton expansion
< 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is less than? (element-wise, singleton expansion) \matlab+<+ (\matlab+lt+), element-wise with singleton expansion. For complex values, the real parts are compared. If $1$ input: a second input is used given by the first transposed
for k = 1:2, if ~isreal(in{k}), in{k} = real(in{k}); end; end; clear k
if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@lt, in{1}, in{2}); else out{1} = in{1} < in{2}; end
X< 1 3 1 1 2 1 [false true] true true true true if numel(in)==2, if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@min, in{1}, in{2}); else out{1} = min(in{1}, in{2}); end; minimum \matlab+min+. If $2$ inputs: element-wise with singleton expansion. With more than $2$ inputs, the second is replaced by \matl+[]+. This function does not support flags \matlab+'omitnan'+ or \matlab+'includenan'+. Output is \matlab+char+ if there is $1$ input and it is \matlab+char+, or if there are $2$ inputs and both are \matlab+char+, or if there are $3$ inputs, second is empty and third is \matlab+char+. \sa \matl+X>+, \matl+Xl+
elseif numel(in)==1, [out{:}] = min(in{:});
else in{2} = []; [out{:}] = min(in{:}); end
if (numel(in)==1 && ischar(in{1})) || (numel(in)==2 && ischar(in{1}) && ischar(in{2})) || (numel(in)==3 && ischar(in{1}) && isempty(in{2})), out{1} = char(out{1}); end
Y< 1 3 1 2 1 1 1 true true true true c = ischar(in{1}); if c, in{1} = double(in{1}); end cumulative minimum \matlab+cummin+. Output is \matlab+char+ if first input is. \sa \matl+Y>+
out{1} = cummin(in{:});
if c, out{1} = char(out{1}); end; clear c
Z<
= 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is equal? (element-wise, singleton expansion) \matlab+==+ (\matlab+eq+), element-wise with singleton expansion. If $1$ input: a second input is used given by the first transposed
if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@eq, in{1}, in{2}); else out{1} = in{1}==in{2}; end
X= 0 inf 2 numel(STACK) 1 1 1 true true true true if numel(in)>=2, out{1} = isequal(in{:}); else out{1} = true; end true if arrays are numerically equal \matlab+isequal+. Works for any number of inputs
Y= 2 2 2 1 1 1 true true true true if isnumeric(in{1}), in{1} = char(in{1}); end; if isnumeric(in{2}), in{2} = char(in{2}); end; out{1} = strcmp(in{:}); compare strings \matlab+strcmp+. If first or second inputs are numeric they are converted to char
Z=
> 1 2 2 1 1 1 1 true true true true if numel(in)==1, in{2} = in{1}.'; end is greater than? (element-wise, singleton expansion) \matlab+>+ (\matlab+gt+), element-wise with singleton expansion. For complex values, the real parts are compared. If $1$ input: a second input is used given by the first transposed
for k = 1:2, if ~isreal(in{k}), in{k} = real(in{k}); end; end; clear k
if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@gt, in{1}, in{2}); else out{1} = in{1} > in{2}; end
X> 1 3 1 1 2 1 [false true] true true true true if numel(in)==2, if ~isa(in{1},'sym')&&~isa(in{2},'sym') out{1} = bsxfun(@max, in{1}, in{2}); else out{1} = max(in{1}, in{2}); end; maximum \matlab+max+. If $2$ inputs: element-wise with singleton expansion. With more than $2$ inputs, the second is replaced by \matl+[]+. This function does not support flags \matlab+'omitnan'+ or \matlab+'includenan'+. Output is \matlab+char+ if there is $1$ input and it is \matlab+char+, or if there are $2$ inputs and both are \matlab+char+, or if there are $3$ inputs, second is empty and third is \matlab+char+. \sa \matl+X<+, \matl+Xl+
elseif numel(in)==1, [out{:}] = max(in{:});
else in{2} = []; [out{:}] = max(in{:}); end
if (numel(in)==1 && ischar(in{1})) || (numel(in)==2 && ischar(in{1}) && ischar(in{2})) || (numel(in)==3 && ischar(in{1}) && isempty(in{2})), out{1} = char(out{1}); end
Y> 1 3 1 2 1 1 1 true true true true c = ischar(in{1}); if c, in{1} = double(in{1}); end cumulative maximum \matlab+cummax+. Output is \matlab+char+ if first input is. \sa \matl+Y<+
out{1} = cummax(in{:});
if c, out{1} = char(out{1}); end; clear c
Z>
?
X?
Y? 0 0 0 1 1 1 true true true true x = { 'V=..90+r~/,~6=..90+~0/*p~J69,9~5+~0/~''6%' 'U*w+~=22~Q=*2=<w+~8=)2*p~U*w+~49=2/)+p~U*w+~6/2:507~19~<=;3}' 'Uw(9~+990~.,/7,=1+~%/)~.9/.29~''/)2:0w*~<9259(9' 'J69~.,/7,=119,~6=+~<990~:,503507r~0/*~19' 'U~:5:~5*~8/,~19p~U~2539:~5*p~U~''=+~7//:~=*~5*' 'E/)~4)+*~6=(90w*~9=,09:~5*~%9*r~<=<%' 'Q%~;/:9~5+~.,/<291=*5;' 'E/)~399.~)+507~*6=*~8)0;*5/0p~U~:/~0/*~*6503~5*~19=0+~''6=*~%/)~*6503~5*~19=0+' 'J65+~5+~/<(5/)+2%~+/19~+*,=079~)+9~/8~*69~8)0;*5/0~wE_w~*6=*~U~''=+0w*~.,9(5/)+2%~=''=,9~/8' 'N,/7,=1+~1=3507~.,/7,=1+~q~6/''~.9,(9,+9}' 'G9~099:~*/~7/~:99.9,' }; if ~numel(in), in{1} = randi(numel(x)); end; if numel(in{1})>1, error('MATL:runtime', 'MATL run-time error: input not allowed'); end; out{1} = char(158-x{mod(in{1}-1,numel(x))+1}); clear x answer why answer why. Sort of
Z? 1 6 3 1 1 1 true true true true charOut = numel(in)==3 && ischar(in{3}); create sparse matrix \matlab+sparse+. If $3$ inputs and third input is \matlab+char+, the output is converted to \matlab+char+
for k = 1:min(3,numel(in)), if ischar(in{k}), in{k} = double(in{k}); end; end
y = sparse(in{:});
if charOut, y = char(full(y)); end
out{1} = y;
clear k charOut y
@
X@
Y@ 1 2 1 2 1 1 1 true true true true if numel(in)==1 all possible permutations / variations If $1$ input: \matlab+perms+. If $2$ inputs: variations (without repetition). In either case, the rows in the result are sorted in ascending order as a group
out{1} = sortrows(perms(in{:}));
else
n = in{2}; combs = cell(1,n);
x = 1:numel(in{1});
[combs{end:-1:1}] = ndgrid(x);
combs = cat(n+1, combs{:}); combs = reshape(combs,[],n);
combs = combs(all(diff(sort(combs,2),[],2),2), :);
combs = in{1}(combs);
combs = reshape(combs, [], n);
out{1} = sortrows(combs); clear combs n x
end
% Variations are computed like Cartesian power (variations with repetitions), and then results with repetitions are removed
Z@ 1 3 1 2 1 1 1 true true true true c = ischar(in{1}); random permutation \matlab+randperm+ (produces a row vector as output). If $3$ inputs: third input indicates number of permutations, each on a different row. If first input is char it is interpreted as population (not as size). \sa \matl+Zr+
if c, x = in{1}; in{1} = numel(in{1}); end
if numel(in)~=3, out{1} = randperm(in{:});
else [~, p] = sort(rand(in{3},in{1}),2); p = p(:,1:in{2}); out{1} = p; end
if c, out{1} = x(out{1}); end
clear p c x
A 1 2 1 2 1 1 1 true true true true out{1} = all(in{:}); all \matlab+all+. \sa \matl|XA|
XA 1 1 1 1 1 1 true true true true out{1} = all(in{:},1); all, along first dimension \matlab+all(..., 1)+. \sa \matl|A|
YA 2 3 2 3 1 1 1 true true true true if islogical(in{2}) && isequal(in{2}, false), in{2} = 0:9; convert integer to string representation in given base (i) \matlab+dec2base+. (ii) If second input has more than one element: it defines the symbols, which can be characters or numbers. The number of symbols defines the base, which can exceed $36$. (iii) If second input is a negative number \matlab+-n+: it is interpreted as symbols \matlab+0:n-1+ (case ii). (i, ii) Base \matl+0+ is interpreted as \matl+10+, \matl+1+ as \matl+16+, \matl+F+ as \matl+0:9+, \matl+T+ as \matl+0:15+. \sa \matl+ZA+, \matl+Za+
elseif islogical(in{2}) && isequal(in{2}, true), in{2} = 0:15;
elseif isnumeric(in{2}) && isequal(in{2}, 0), in{2} = 10;
elseif isnumeric(in{2}) && isequal(in{2}, 1), in{2} = 16;
elseif isnumeric(in{2}) && isscalar(in{2}) && in{2}<0, in{2} = 0:-in{2}-1;
end
if numel(in{2})==1, out{1} = dec2base(in{:});
else d = in{1}(:); symbols = in{2}(:).'; b = numel(symbols);
if ~(isnumeric(d) || ischar(d)) || any(d ~= floor(d)) || any(d < 0) || any(d > 1/eps)
error(message('MATLAB:dec2base:FirstArg')); end
if numel(in)>2 && (~isscalar(in{3}) || ~(isnumeric(in{3}) || ischar(in{3})) || in{3} ~= floor(in{3}) || in{3} < 0)
error(message('MATLAB:dec2base:ThirdArg')); end
if isempty(d)
out{1} = [];
else
d = double(d);
n = max(1,round(log2(max(d)+1)/log2(b)));
while any(b.^n <= d), n = n + 1; end
if numel(in)>2, n = max(n,in{3}); end
s(:,n) = rem(d,b);
while any(d) && n >1, n = n - 1; d = floor(d/b); s(:,n) = rem(d,b); end
s = reshape(symbols(s + 1),size(s));
out{1} = s;
clear d n b s
end
end
% Adapted from dec2base
ZA 2 2 2 1 1 1 true true true true if islogical(in{2}) && isequal(in{2}, false), in{2} = 0:9; convert string in given base to decimal integer (i) \matlab+base2dec+. (ii) If second input has more than one element: it defines the symbols, which can be characters (case-sensitive) or numbers. The number of symbols defines the base, which can exceed $36$. (iii) If second input is a negative number \matlab+-n+: it is interpreted as symbols \matlab+0:n-1+ (case ii). (i, ii, iii) Non-recognized digits are ignored. Base \matl+0+ is interpreted as \matl+10+, \matl+1+ as \matl+16+, \matl+F+ as \matl+0:9+, \matl+T+ as \matl+0:15+. \sa \matl+YA+, \matl+Za+
elseif islogical(in{2}) && isequal(in{2}, true), in{2} = 0:15;
elseif isnumeric(in{2}) && isequal(in{2}, 0), in{2} = 10;
elseif isnumeric(in{2}) && isequal(in{2}, 1), in{2} = 16;
elseif isnumeric(in{2}) && isscalar(in{2}) && in{2}<0, in{2} = 0:-in{2}-1;
end
x = in{1};
a = in{2}; if numel(a)==1; b = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; a=b(1:a); x = upper(x); end
if ~iscell(x), x = mat2cell(x, ones(size(x,1),1), size(x,2)); end
y = NaN(numel(x),1);
for n = 1:numel(x)
[tf, ind] = ismember(x{n}, a);
ind = ind(tf);
y(n) = polyval(ind-1, numel(a));
end
out{1} = y; clear tf ind x y
B 1 2 1 2 1 1 1 true true true true out{1} = logical(dec2bin(in{:})-'0'); convert from decimal to binary. Produces a logical vector \matlab|logical(dec2bin(...)-'0')|. \sa \matl|YB|
XB 1 1 1 1 1 1 true true true true if ~iscell(in{1}) convert from binary to decimal \matlab|bin2dec(char(logical(...)+'0'))|. Works also for cell array input. \sa \matl|ZB|
out{1} = bin2dec(char(logical(in{1})+'0'));
else
out{1} = cellfun(@(x) bin2dec(char(logical(x)+'0')), in{1});
end
YB 1 2 1 2 1 1 1 true true true true out{1} = dec2bin(in{:}); convert decimal number to binary string \matlab|dec2bin|. \sa \matl|B|
ZB 1 1 1 1 1 1 true true true true out{1} = bin2dec(in{1}); convert binary string to decimal number \matlab|bin2dec|. \sa \matl|XB|
C
XC
YC 2 4 2 1 1 1 true true true true if numel(in{2})==1, if size(in{1},1)==1, in{2} = [1 in{2}]; else in{2} = [in{2} 1]; end; end rearrange array blocks into columns \matlab+im2col+. If the second input is a scalar \matlab+n+, it is transformed into \matlab+[1 n]+ if the first input is a row vector, or to \matlab+[n 1]+ otherwise. First input can also be a cell array. \sa \matl+ZC+
if iscell(in{1})
x = reshape(1:numel(in{1}), size(in{1}));
y = im2col(x, in{2:end});
y = in{1}(y);
out{1} = y; clear x y
else
out{1} = im2col(in{:});
end
ZC 2 3 2 1 1 1 true true true true if numel(in{2})==1, if size(in{1},1)==1, in{2} = [1 in{2}]; else in{2} = [in{2} 1]; end; end rearrange distinct array blocks into columns \matlab+im2col(..., 'distinct')+. If the second input is a scalar n, it is transformed into [1 n] if the first input is a row vector, or to [n 1] otherwise. First input can also be a cell array. \sa \matl+YC+
in{end+1} = 'distinct';
if iscell(in{1})
x = reshape(1:numel(in{1}), size(in{1}));
y = im2col(x, in{2:end});
y = in{1}(y);
out{1} = y; clear x y
else
out{1} = im2col(in{:});
end
D 0 inf 1 0 1 0 1 true true true true if nout==0 convert to string and display / string representation (i) With $0$ outputs: If $1$ input: \matlab+disp(num2str(..., '%.15g '))+. If several inputs: \matlab+disp(num2str(eachInput,lastInput))+, where \matlab+eachInput+ loops over all inputs but the last. In either case, (nested) cell arrays are (recursively) unboxed in linear order. Most characters below 32 are replaced by space. Symbolic data is displayed directly. (ii) With $1$ output: \matlab+mat2str+. Empty arrays are always shown as \matlab+[]+, \matlab+''+ or \matlab+{}+. Most input characters below 32 are replaced by space. Cell arrays are converted to string representation too. Optional second, third and fourth inputs respectively specify column separator, row separator and whether the separators should be used for non-cell arrays too. Second and third inputs are converted to char if needed. \sa \matl+XD+, \matl+YD+, \matl+ZD+
if numel(in)==1, data = in; fmt = {'%.15g '}; else data = in(1:end-1); fmt = in(end); end
kk = cellfun(@iscell, data);
while any(kk)
data(~kk) = num2cell({data{~kk}}); kk = kk(:).';
for k = find(kk), data{k} = data{k}(:); end
data = vertcat(data{:}); kk = cellfun(@iscell, data);
end
for k = 1:numel(data), if ~isa(data{k}, 'sym'), d = num2str(data{k}, fmt{:}); d(ismember(d,replaceBySpace)) = ' '; else d = data{k}; end, disp(d), end
clear data kk k d fmt
else
if numel(in)<4, sep_noncell = false; else sep_noncell = in{4}; end
if numel(in)<3, row_sep = '; '; else row_sep = in{3}; end
if numel(in)<2, col_sep = ' '; else col_sep = in{2}; end
x = in{1};
x = {x}; y = {[]}; done = false;
while ~done
done = true;
for n = 1:numel(y);
if isempty(y{n})
done = false;
if ~iscell(x{1})
if isempty(x{1}), if ischar(x{1}), s = ''''''; else, s = '[]'; end; else, if ischar(x{1}), x{1}(ismember(x{1},replaceBySpace)) = ' '; end; s = mat2str(x{1}); end
if sep_noncell
for k = flip(find(~mod(cumsum(s==''''),2) & s==' ')), s = [s(1:k-1) col_sep s(k+1:end)]; end
for k = flip(find(~mod(cumsum(s==''''),2) & s==';')), s = [s(1:k-1) row_sep s(k+1:end)]; end
end
y{n} = s; x(1) = [];
else
str = ['{' repmat([{[]}, col_sep], 1, numel(x{1})) '}'];
ind_sep = find(cellfun(@(t) isequal(t, col_sep), str));
if ~isempty(ind_sep)
str(ind_sep(end)) = [];
ind_sep(end) = [];
end
step_sep = size(x{1}, 2);
str(ind_sep(step_sep:step_sep:end)) = {row_sep};
y = [y(1:n-1) str y(n+1:end)]; x = [reshape(x{1}.', 1, []) x(2:end)];
end
end
end
end
y = [y{:}];
out{1} = y;
clear x sep_noncell row_sep col_sep done s k str inde_sep step_sep y
end
XD 0 inf numel(STACK) 1 0 0 0 true true true true data = in; convert to string and display \matlab+disp(num2str(eachInput, '%.15g '))+, where \matlab+eachInput+ loops over all inputs. (Nested) cell arrays are (recursively) unboxed in linear order. Most characters below 32 are replaced by space. Symbolic data is displayed directly. \sa \matl+D+, \matl+YD+, \matl+ZD+
kk = cellfun(@iscell, data);
while any(kk)
data(~kk) = num2cell({data{~kk}}); kk = kk(:).';
for k = find(kk), data{k} = data{k}(:); end
data = vertcat(data{:}); kk = cellfun(@iscell, data); end
for k = 1:numel(data), if ~isa(data{k}, 'sym'), d = num2str(data{k}, '%.15g '); d(ismember(d,replaceBySpace)) = ' '; else d = data{k}; end, disp(d), end
clear data kk k
YD 1 inf 2 1 0 2 1 0 true true true true if numel(out), [out{:}] = sprintf(in{end}, in{1:end-1}); write formatted data to string \matlab+sprintf+ with format string as last input. If $0$ outputs: prints to screen using \matlab+fprintf(...)+. \sa \matl+D+, \matl+XD+, \matl+ZD+
else fprintf(in{:}); end
ZD 0 inf 1 0 0 0 true true true true for k = 1:numel(in), if ischar(in{k}), in{k}(ismember(in{k},replaceBySpace)) = ' '; end, disp(in{k}), end display \matlab+disp+ for each input. For char input, most characters below 32 are replaced by space. \sa \matl+D+, \matl+XD+, \matl+YD+
E 1 1 1 1 1 1 true true true true out{1} = in{1}*2; multiply by 2 \matlab|(...)*2|
XE 3 3 3 1 1 1 true true true true if numel(in{3})==1, in{3} = repmat(in{3}, size(in{2})); end replace elements in numeric or char array With numeric or char inputs, replace in first input all occurrences of each element of the second input by the corresponding element of the third input. The third input may be longer than the second, and then the extra elements are ignored. Or it may have a single element, and then it is implicitly replicated. Output has the same class and size as the first input. If the three inputs are cell arrays of strings (the second may also be a string instead of a cell array of strings), each string of the first input is considered atomic, that is, replacing is based on whole strings. If the first input is a cell array and the others are numeric or char, replacing is done on each cell's contents as if the cell's contents were the first input
if ~(iscell(in{1}) && ~iscell(in{2}) && ~iscell(in{3}))
[ii, jj] = ismember(in{1}, in{2}); y = in{1}; y(ii) = in{3}(jj(ii)); out{1} = y; clear ii jj y
else
z = cell(size(in{1}));
for k = 1:numel(in{1})
x = in{1}{k};
[ii, jj] = ismember(x, in{2}); y = x; y(ii) = in{3}(jj(ii)); z{k} = y;
end
out{1} = z; clear ii jj x y
end
YE
ZE 1 4 1 2 1 1 1 true true true true if numel(in)<=3 N-dimensional inverse discrete Fourier transform (IFFT) (i) With $1$, $2$ or $3$ inputs: \matlab+ifftn+. If first input is a vector and second input is a scalar, a $1$ is prepended or appended to the second input according to the vector orientation (so the result is the same as that of \matlab+ifft+). (ii) With $4$ inputs: \matlab+ifft+
if numel(in)>=2 && isvector(in{1}) && isscalar(in{2}), if size(in{1},1)==1, in{2} = [1 in{2}]; else in{2} = [in{2} 1]; end, end
out{1} = ifftn(in{:});
elseif numel(in)==4
out{1} = ifft(in{:});
else
error('MATL:runtime', 'MATL run-time error: incorrect number of inputs')
end
F
XF
YF 1 1 1 1 2 1 2 true true true true trim = (any(in{1}<0) && (nout==1)) || (~any(in{1}<0) && (nout==2)); in{1} = abs(in{1}); Exponents of prime factor decomposition (i) With $1$ output: exponents of prime factor decomposition, without skipping primes. If the input is a numeric array it is linearized, and each result is in an output row. If any entry in the input is negative, the absolute value is taken, and the output contains only non-zero exponents. (ii) With $2$ outputs: first output gives the prime factors, second gives the exponents. Primes that are not factors are skipped, as are their zero exponents. If any entry in the input is negative, the absolute value is taken, and all intermediate primes are included, possibly with zero exponents. \sa \matl+Yf+
f = arrayfun(@factor, in{1}, 'uniformoutput', false);
p = primes(max([f{:}]));
y = zeros(numel(f), numel(p));
for k = 1:numel(f);
y(k,:) = sum(bsxfun(@eq, f{k}(:), p), 1);
end
if nout==1, out{1} = y;
elseif nout==2, out = {p, y};
else error('MATL:runtime', 'MATL run-time error: number of outputs not supported');
end
if trim, out = cellfun(@(c) c(:, any(y>0, 1)), out, 'UniformOutput', false); end
clear f p y k trim
ZF 1 3 1 2 1 1 1 true true true true if numel(in)<=2 N-dimensional discrete Fourier transform (FFT) (i) With $1$ or $2$ inputs: \matlab+fftn+. If first input is a vector and second input is a scalar, a $1$ is prepended or appended to the second input according to the vector orientation (so the result is the same as that of \matlab+fft+). (ii) With $3$ inputs: \matlab+fft+
if numel(in)==2 && isvector(in{1}) && isscalar(in{2}), if size(in{1},1)==1, in{2} = [1 in{2}]; else in{2} = [in{2} 1]; end, end
out{1} = fftn(in{:});
elseif numel(in)==3
out{1} = fft(in{:});
else
error('MATL:runtime', 'MATL run-time error: incorrect number of inputs')
end
G 0 1 double(numel(CB_G)>1) 0 0 inf 1+(max(numel(CB_G),1)-1)*(numel(in)==0) true true false true if numel(CB_G)==0 paste from user-input clipboard G paste from user-input clipboard G. If $0$ input arguments: addresses all levels. If $1$ input argument: addresses specified level. In either of those cases, if clipboard G has no levels one user-input is implicitly taken to fill the first level
implInput = input(implicitInputPrompt,'s');
valid = isempty(regexp(implInput, '^[^'']*(''[^'']*''[^'']*)*[a-df-hk-zA-EG-MOQ-SU-XZ]', 'once')) && isempty(regexp(implInput, '^[^'']*(''[^'']*''[^'']*)*[a-zA-Z]{2}', 'once'));
assert(valid, 'MATL:runner', 'MATL run-time error: input not allowed')
if isempty(implInput), implInput = []; else implInput = eval(implInput); end
CB_G{1} = implInput;
end
if numel(in)==0, out = CB_G(1:nout); else out = CB_G(mod(in{1}-1,numel(CB_G))+1); end; clear implInput valid
XG 1 inf 1 2 0 0 0 true true true true plot(in{:}); if (numel(in)==1 && ~isreal(in{1})) || (numel(in)>1 && ~isreal(in{1}) && ischar(in{2})), axis equal; end; drawnow plot \matlab+plot+. Calls \matlab+drawnow+ to update figure immediately. With one input, or with several inputs the second of which is a string: if the first input is complex (even with zero imaginary part), \matlab+axis equal+ is also called.
YG 2 inf 2 3 0 0 0 true true true true if (isnumeric(in{end}) || islogical(in{end})) && numel(in{end})~=1 display or save image \matlab+imwrite+, \matlab+imagesc+, \matlab+image+ or \matlab+imshow+. (i) If last input is a scalar: \matlab+0+ corresponds to \matlab+imwrite+, \matlab+1+ to \matlab+imagesc+, \matlab+2+ to \matlab+image+ and \matlab+3+ to \matlab+imshow+. The corresponding function is called with the remaining inputs. (ii) If last input is numeric or logical and not a scalar: \matlab+imshow+ is called with all inputs. (iii) If last input is char: \matlab+imwrite+ is called with all inputs. (i, iii) For \matlab+imwrite+, the first input of type char is interpreted as file name. If it has no extension '.png' is added; if it's empty it is replaced by 'image.png'; and if non existent 'image.png' is used as final input. (i, ii, iii) For \matl+imshow+ and \matl+imwrite+, if the second input is logical it is converted to \matlab+double+. If it is numeric, has the shape of a colormap, and has some entry greater than $1$, it is normalized by converting to \matlab+uint8+, then to \matlab+double+, and then dividing by $255$. For \matlab+imagesc+ and \matlab+image+, the function call is followed by \matlab+axis ij, axis image+. For \matlab+imagesc+, \matlab+image+ and \matlab+imshow+, \matlab+drawnow+ is called to update figure immediately
if islogical(in{2}), in{2} = double(in{2}); end
if numel(in)>=2 && isnumeric(in{2}) && ndims(in{2})==2 && size(in{2},2)==3 && any(in{2}(:)>1), in{2} = double(uint8(in{2}))/255; end
imshow(in{:}); drawnow
elseif ischar(in{end})
k = find(cellfun(@ischar, in),1);
if isempty(in{k}), in{k} = 'image.png'; end;
if isempty(regexp(in{k}, '\..+$', 'once')), in{k} = [in{k} '.png']; end
if islogical(in{2}), in{2} = double(in{2}); end
if numel(in)>=2 && isnumeric(in{2}) && ndims(in{2})==2 && size(in{2},2)==3 && any(in{2}(:)>1), in{2} = double(uint8(in{2}))/255; end
imwrite(in{:}); clear k
else
switch(in{end})
case 0
k = find(cellfun(@ischar, in),1);
if isempty(k)
in{end+1} = in{end}; in{end-1} = 'image.png';
else
if isempty(in{k}), in{k} = 'image.png'; end;
if isempty(regexp(in{k}, '\..+$', 'once')), in{k} = [in{k} '.png']; end
end
if numel(in)>=3 && isnumeric(in{2}) && ndims(in{2})==2 && size(in{2},2)==3 && any(in{2}(:)>1), in{2} = double(uint8(in{2}))/255; end
imwrite(in{1:end-1}); clear k
case 1
imagesc(in{1:end-1}); axis ij, axis image, drawnow
case 2
image(in{1:end-1}); axis ij, axis image, drawnow
case 3
if numel(in)>=3 && isnumeric(in{2}) && ndims(in{2})==2 && size(in{2},2)==3 && any(in{2}(:)>1), in{2} = double(uint8(in{2}))/255; end
imshow(in{1:end-1}); drawnow
otherwise
error('MATL:runtime', 'MATL run-time error: unrecognized last input');
end
end
ZG 1 inf 2 3 0 1 0 true true true true switch in{end} control appearance of graphics / format Depending on numeric last input, calls a graphic function or \matlab+format+ with the remaining inputs. $0$: \matlab+format+. $1$: \matlab+axis+. Calls \matlab+drawnow+ to update figure immediately. Flag strings in first to second-last inputs can be replaced by numbers, as follows: 1: \matlab+'equal'+, 2: \matlab+'image'+, 3: \matlab+'square'+, 4: \matlab+'ij'+, 5: \matlab+'xy'+, 6: \matlab+'normal'+, 7: \matlab+'off'+, 8: \matlab+'on'+, 9: \matlab+'tight'+, 10: \matlab+'manual'+, 11: \matlab+'fill'+, 12: \matlab+'auto'+, 13: \matlab+'vis3d'+. $2$: \matlab+colormap+. If the first input is numeric, has the shape of a colormap, and has some entry greater than $1$, it is normalized by converting to \matlab+uint8+, then to \matlab+double+, and then dividing by $255$. With $3$ inputs (including the last input 2), the second input specifies colormap size. With $0$ outputs, calls \matlab+drawnow+ to update figure immediately. $3$: \matlab+hold+. Flag strings in first input can be replaced by numbers, as follows: 1: \matlab+'on'+, 2: \matlab+'off'+. $4$: \matlab+grid+. Flag strings in first input can be replaced by numbers, as follows: 1: \matlab+'on'+, 2: \matlab+'off'+. $5$: \matlab+colorbar+. If the first input is logical (not necessarily scalar) it activates or deactivates the colorbar
case 0
format(in{1:end-1});
case 1
str = {'equal' 'image' 'square' 'ij' 'xy' 'normal' 'off' 'on' 'tight' 'manual' 'fill' 'auto' 'vis3d'};
for k = 1:numel(in)-1, if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear k str
[out{:}] = axis(in{1:end-1}); drawnow
case 2
if numel(in)>=2 && isnumeric(in{1}) && ndims(in{1})==2 && size(in{1},2)==3 && any(in{1}(:)>1), in{1} = double(uint8(in{1}))/255; end
if numel(in)==3
switch in{1}
case 'autumn', cmap = autumn(in{2});
case 'bone', cmap = bone(in{2});
case 'colorcube', cmap = colorcube(in{2});
case 'cool', cmap = cool(in{2});
case 'copper', cmap = copper(in{2});
case 'flag', cmap = flag(in{2});
case 'gray', cmap = gray(in{2});
case 'hot', cmap = hot(in{2});
case 'hsv', cmap = hsv(in{2});
case 'jet', cmap = jet(in{2});
case 'lines', cmap = lines(in{2});
case 'pink', cmap = pink(in{2});
case 'parula', cmap = parula(in{2});
case 'prism', cmap = prism(in{2});
case 'spring', cmap = spring(in{2});
case 'summer', cmap = summer(in{2});
case 'winter', cmap = winter(in{2});
otherwise
error('MATL: runtime', 'MATL runtime error: unrecognized name for creating colormap')
end
[out{:}] = colormap(cmap); if isempty(out), drawnow, end
else
[out{:}] = colormap(in{1:end-1}); if isempty(out), drawnow, end
end
case 3
str = {'on' 'off'};
if numel(in)>1 && isnumeric(in{1}), in(1) = str(in{1}); end; clear k str
hold(in{1:end-1})
case 4
str = {'on' 'off'};
if numel(in)>1 && isnumeric(in{1}), in(1) = str(in{1}); end; clear k str
grid(in{1:end-1})
case 5
if numel(in)==2 && islogical(in{1}), if in{1} colorbar, else colorbar off, end
else
colorbar(in{1:end-1})
end
otherwise
error('MATL:runtime', 'MATL run-time error: unrecognized last input');
end
H 0 0 0 0 inf numel(CB_H) true true false true out = CB_H(1:nout); paste from clipboard H paste from clipboard H
XH 0 inf 1 2 0 0 0 false true false true CB_H = in; copy to clipboard H copy to clipboard H
YH 1 inf 2 4 0 0 0 true true true true switch in{end} advanced plotting functions Depending on numeric last input, calls a plotting function with the remaining inputs. $0$: \matlab+plot3+. $1$: \matlab+surf+. $2$: \matlab+mesh+. $3$: \matlab+stem+. $4$: \matlab+stairs+. $5$: \matlab+bar+. $6$: \matlab+loglog+. After that, \matlab+drawnow+ is called to update figure immediately
case 0
plot3(in{1:end-1});
case 1
surf(in{1:end-1});
case 2
mesh(in{1:end-1});
case 3
stem(in{1:end-1});
case 4
stairs(in{1:end-1});
case 5
bar(in{1:end-1});
case 6
loglog(in{1:end-1});
otherwise
error('MATL:runtime', 'MATL run-time error: unrecognized last input');
end
drawnow
ZH
I 0 0 0 0 inf numel(CB_I) true true false true out = CB_I(1:nout); paste from clipboard I paste from clipboard I
XI 0 inf 1 0 0 0 false true false true CB_I = in; copy to clipboard I copy to clipboard I
YI 3 4 3 4 1 1 1 true true true true str = {'distinct' 'sliding'}; rearrange matrix columns into blocks \matlab+col2im+. Uses \matlab+'distinct'+ option by default. Second and third inputs may be scalars, and then they are interpreted as numbers of columns. Third input may be a two-vector with product less then the number of elements of first input, and then it is appropriately scaled. This function allows flag strings in fourth input to be replaced by numbers, as follows: 1: \matlab+'distinct'+, 2: \matlab+'sliding'+
if numel(in)>=4, if isnumeric(in{4}), in(4) = str(in{4}); end; end; clear str
if numel(in)<4, in{4} = 'distinct'; end
if isscalar(in{2}), in{2}(2) = size(in{1},1)/in{2}; end
if isscalar(in{3}), in{3}(2) = numel(in{1})/in{3}; end
if prod(in{3})~=numel(in{1}), in{3} = round(in{3}*sqrt(numel(in{1})/prod(in{3}))); end
out{1} = col2im(in{:});
ZI 1 inf 2 3 1 inf 1 true true true true switch in{end} image processing functions Depending on numeric last input, calls an image processing function with the remaining inputs. $0$: \matlab+imfill+. If first input is logical or numerical it is converted to char. $1$: \matlab+bwlabeln+. $2$: \matlab+imdilate+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $3$: \matlab+imerode+. This function allows second input to be number $4$, $5$, $8$ or $9$, which is interpreted as the corresponding neighbourhood mask. $4$: \matlab+bweuler+. $5$: \matlab+bwselect+ with $4$ inputs and $1$ output.
case 0
if islogical(in{1}) || ischar(in{1}), in{1} = double(in{1}); end
[out{:}] = imfill(in{1:end-1});
case 1
[out{:}] = bwlabeln(in{1:end-1});
case 2
mask = {NaN NaN NaN [false true false; true false true; false true false] [false true false; true true true; false true false] NaN NaN [true true true; true false true; true true true] [true true true; true true true; true true true]};
if isnumeric(in{2}), in(2) = mask(in{2}); end; clear mask
[out{:}] = imdilate(in{1:end-1});
case 3
mask = {NaN NaN NaN [false true false; true false true; false true false] [false true false; true true true; false true false] NaN NaN [true true true; true false true; true true true] [true true true; true true true; true true true]};
if isnumeric(in{2}), in(2) = mask(in{2}); end; clear mask
[out{:}] = imerode(in{1:end-1});
case 4
[out{:}] = bweuler(in{1:end-1});
case 5
assert(numel(in)==5, 'MATL:runtime', 'MATL run-time error: ''bwselect'' is only supported with 4 inputs')
[out{:}] = bwselect(in{1:end-1});
otherwise
error('MATL:runtime', 'MATL run-time error: unrecognized last input');
end
J 0 0 0 0 inf numel(CB_J) true true false true out = CB_J(1:nout); paste from clipboard J paste from clipboard J
XJ 0 inf 1 0 0 0 false true false true CB_J = in; copy to clipboard J copy to clipboard J
YJ
ZJ 1 inf 2 3 0 inf 1 true true true true assert(strcmp(class(in{1}), 'sym'), 'MATL:runtime', 'MATL run-time error: first input is not symbolic') symbolic-specific functions Depending on numeric last input, calls a symbolic-specific function with the remaining inputs. $0$: \matlab+simplify+. $1$: \matlab+pretty+. $2$: \matlab+latex+. $3$: \matlab+numden+. \sa \matl+X$+
switch in{end}
case 0
[out{:}] = simplify(in{1:end-1});
case 1
[out{:}] = pretty(in{1:end-1});
case 2
[out{:}] = latex(in{1:end-1});
case 3
[out{:}] = numden(in{1:end-1});
otherwise
error('MATL:runtime', 'MATL run-time error: unrecognized last input');
end
K 0 0 0 0 inf numel(CB_K) true true false true out = CB_K(1:nout); paste from clipboard K paste from clipboard K
XK 0 inf 1 0 0 0 false true false true CB_K = in; copy to clipboard K copy to clipboard K
YK
ZK
L 1 1 1 0 inf numel(CB_L{in{1}}) true true false true out = [CB_L{in{1}}(1:nout)]; paste from multi-level clipboard L paste from multi-level clipboard L. Input specifies level
XL 1 inf 2 3 0 0 0 false true false true CB_L{in{end}} = in(1:end-1); STACK(end+nin(end)) = []; copy to multi-level clipboard L copy to multi-level clipboard L. Last input specifies level
YL 1 inf 2 3 1 inf 1 true true true true str = {'spiral' 'pascal' 'magic' 'hadamard' 'circul' 'gcdmat' 'minij' 'hilb' 'invhilb' 'tridiag' 'ris'}; Higham test matrices and other matrices \matlab+gallery+ with matrix name as last input. Also includes \matlab+magic+, \matlab+hilb+, \matlab+invhilb+, \matlab+hadamard+, \matlab+pascal+, \matlab+spiral+. This function allows some strings in last input to be replaced by numbers, as follows: 1: \matlab+'spiral'+, 2: \matlab+'pascal'+, 3: \matlab+'magic'+, 4: \matlab+'hadamard'+, 5: \matlab+'circul'+, 6: \matlab+'gcdmat'+, 7: \matlab+'minij'+, 8: \matlab+'hilb'+, 9: \matlab+'invhilb'+, 10: \matlab+'tridiag'+, 11: \matlab+'ris'+
if isnumeric(in{end}), in(end) = str(in{end}); end; clear str
switch in{end}
case {'magic', 'hilb', 'invhilb', 'hadamard', 'pascal', 'spiral'}
[out{1}] = feval(in{end},in{1:end-1});
otherwise
[out{:}] = gallery(in{end}, in{1:end-1});
end
ZL
M 1 1 1 0 inf 1+(in{1}<=numCbM)*(numel(CB_M{mod(in{1}-1,numCbM)+1})-1) true true false true if in{1}>=1 && in{1}<=numCbM paste from function-input clipboard M paste from function-input clipboard M. Input specifies level ($1$ to $4$) or individual input ($5$ or larger)
out = [CB_M{in{1}}(1:nout)];
elseif in{1}>numCbM
cbMflip = CB_M(end:-1:1); cbMIndivIn = [cbMflip{cellfun(@numel, cbMflip)>1}]; cbMIndivIn = cbMIndivIn(end:-1:1);
if in{1}-numCbM<=numel(cbMIndivIn), out = cbMIndivIn(in{1}-numCbM); else out = {}; end
clear cbMflip cbMIndivIn
else
error('MATL:runtime', 'MATL run-time error: incorrect input')
end
XM 1 2 1 1 3 1 [false true] true true true true if ~iscell(in{1}) mode (most frequent value) \matlab+mode+. First input can be a cell array of strings
[out{:}] = mode(in{:});
else
[x, ~, y] = unique(in{1}(:));
[out{:}] = mode(y, in{2:end});
out{1} = x(out{1});
if nout>=3, out{3} = x([out{3}{:}]); end
end
YM
ZM
N 0 0 0 1 1 1 true true false true out{1} = numel(STACK); number of elements in the stack number of elements in the stack
XN 2 2 2 1 1 1 true true true true if numel(in{1})<in{2} || ~(in{2}>0) all combinations \matlab+nchoosek+. This interprets first input as an array (even if it is a single number). For inputs \matlab+x+ and \matlab+k+, if \matlab+x+ has less than \matlab+k+ elements or if \matlab+k+ is non-positive the result is an empty array. \sa \matl|Xn|
out{1} = [];
else out{1} = nchoosek(in{:});
end
YN 0 inf 0 1 1 1 true true true true out{1} = NaN(in{:}); not-a-number \matlab+NaN+ function. If $0$ inputs: produces literal \matlab+NaN+.
ZN 1 1 1 1 1 1 true true true true out{1} = isnan(in{:}); true for not-a-number \matlab+isnan+
O 0 inf 0 2 1 1 1 true true true true if numel(in)==0, out{1} = 0; else out{1} = zeros(in{:}); end array of zeros \matlab+zeros+ (if $0$ inputs: produces output $0$)
XO 1 4 2 1 1 1 true true true true out{1} = datestr(in{:}); string representation of date \matlab+datestr+. \sa \matl+YO+, \matl+ZO+
YO 1 6 1 2 1 1 1 true true true true if numel(in)==2 && isnumeric(in{2}), str = {'dd-mmm-yyyy HH:MM:SS' 'dd-mmm-yyyy' 'mm/dd/yy' 'mmm' 'm' 'mm' 'mm/dd' 'dd' 'ddd' 'd' 'yyyy' 'yy' 'mmmyy' 'HH:MM:SS' 'HH:MM:SS PM' 'HH:MM' 'HH:MM PM' 'QQ-YY' 'QQ' 'dd/mm' 'dd/mm/yy' 'mmm.dd,yyyy HH:MM:SS' 'mmm.dd,yyyy' 'mm/dd/yyyy' 'dd/mm/yyyy' 'yy/mm/dd' 'yyyy/mm/dd' 'QQ-YYYY' 'mmmyyyy' 'yyyy-mm-dd' 'yyyymmddTHHMMSS' 'yyyy-mm-dd HH:MM:SS'};in(2) = str(in{2}+1); end; clear str serial date number \matlab+datenum+. With $2$ inputs, if the second input is numeric it is interpreted as a format specifier as in \matlab+datestr+. \sa \matl+XO+, \matl+ZO+
out{1} = datenum(in{:});
ZO 1 3 1 2 1 6 1 true true true true [out{:}] = datevec(in{:}); date components \matlab+datevec+. \sa \matl+XO+, \matl+YO+
P 1 2 1 2 1 1 1 true true true true out{1} = flip(in{:}); flip the order of elements \matlab+flip+. \sa \matl+XP+
XP 1 1 1 1 1 1 true true true true out{1} = flipud(in{:}); flip array in up-down direction \matlab+flipud+. \sa \matl+P+
YP 0 0 0 1 1 1 true true true true out{1} = pi; pi \matlab+pi+
ZP 1 5 2 3 1 2 1 true true true true if numel(in)==1 && nout==1 pairwise distances between two sets of points / entries below diagonal (i) \matlab+pdist2+. Only predefined distance functions are allowed. This function allows flag strings in the third input to be replaced by numbers, as follows: 1: \matlab+'cityblock'+, 2: \matlab+'hamming'+, 3: \matlab+'chebychev'+, 4: \matlab+'correlation'+, 5: \matlab+'cosine'+, 6: \matlab+'seuclidean'+, 7: \matlab+'minkowski'+, 8: \matlab+'mahalanobis'+, 9: \matlab+'spearman'+, 10: \matlab+'jaccard'+, 11: \matlab+'euclidean'+. (ii) With $1$ input and $1$ output: row vector containing all entries below the main diagonal of a matrix
y = in{1}(tril(true(size(in{1})),-1)); y = y(:).';
out{1} = y; clear y
else
str = {'cityblock' 'hamming' 'chebychev' 'correlation' 'cosine' 'seuclidean' 'minkowski' 'mahalanobis' 'spearman' 'jaccard' 'euclidean'};
for k = 3:min(numel(in),3), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str