comparison doc/interpreter/container.txi @ 9209:923c7cb7f13f

Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction. spellchecked all .txi and .texi files.
author Rik <rdrider0-list@yahoo.com>
date Sun, 17 May 2009 12:18:06 -0700
parents 58604c45ca74
children 0f7480d07f6a
comparison
equal deleted inserted replaced
9208:cb163402bf79 9209:923c7cb7f13f
320 Elements can be deleted from a structure array in a similar manner to a 320 Elements can be deleted from a structure array in a similar manner to a
321 numerical array, by assigning the elements to an empty matrix. For 321 numerical array, by assigning the elements to an empty matrix. For
322 example 322 example
323 323
324 @example 324 @example
325 @group
326 in = struct ("call1", @{x, Inf, "last"@}, 325 in = struct ("call1", @{x, Inf, "last"@},
327 "call2", @{x, Inf, "first"@}); 326 "call2", @{x, Inf, "first"@});
328 in (1, :) = [] 327 in (1, :) = []
329 @result{} in = 328 @result{} in =
330 @{ 329 @{
341 [1] = Inf 340 [1] = Inf
342 [2] = first 341 [2] = first
343 ,) 342 ,)
344 343
345 @} 344 @}
346 @end group
347 @end example 345 @end example
348 346
349 @node Creating Structures 347 @node Creating Structures
350 @subsection Creating Structures 348 @subsection Creating Structures
351 349
369 If the values passed to @code{struct} are a mix of scalar and cell 367 If the values passed to @code{struct} are a mix of scalar and cell
370 arrays, then the scalar arguments are expanded to create a 368 arrays, then the scalar arguments are expanded to create a
371 structure array with a consistent dimension. For example 369 structure array with a consistent dimension. For example
372 370
373 @example 371 @example
374 @group
375 struct ("field1", @{1, "one"@}, "field2", @{2, "two"@}, 372 struct ("field1", @{1, "one"@}, "field2", @{2, "two"@},
376 "field3", 3) 373 "field3", 3)
377 @result{} ans = 374 @result{} ans =
378 @{ 375 @{
379 field1 = 376 field1 =
396 [1] = 3 393 [1] = 3
397 [2] = 3 394 [2] = 3
398 ,) 395 ,)
399 396
400 @} 397 @}
401 @end group
402 @end example 398 @end example
403 399
404 @DOCSTRING(struct) 400 @DOCSTRING(struct)
405 401
406 @DOCSTRING(isstruct) 402 @DOCSTRING(isstruct)
556 of the cell array through a vector of positive integers. In the 552 of the cell array through a vector of positive integers. In the
557 following example two cell arrays of equal size are created, and the size 553 following example two cell arrays of equal size are created, and the size
558 of the first one is displayed 554 of the first one is displayed
559 555
560 @example 556 @example
557 @group
561 c1 = cell(3, 4, 5); 558 c1 = cell(3, 4, 5);
562 c2 = cell( [3, 4, 5] ); 559 c2 = cell( [3, 4, 5] );
563 size(c1) 560 size(c1)
564 @result{} ans = 561 @result{} ans =
565 3 4 5 562 3 4 5
563 @end group
566 @end example 564 @end example
567 565
568 @noindent 566 @noindent
569 As can be seen, the @code{size} function also works for cell arrays. As 567 As can be seen, the @code{size} function also works for cell arrays. As
570 do the other functions describing the size of an object, such as 568 do the other functions describing the size of an object, such as
571 @code{length}, @code{numel}, @code{rows}, and @code{columns}. 569 @code{length}, @code{numel}, @code{rows}, and @code{columns}.
572 570
573 As an alternative to creating empty cell arrays, and then filling them, it 571 As an alternative to creating empty cell arrays, and then filling them, it
574 is possible to convert numerical arrays into cell arrays using the 572 is possible to convert numerical arrays into cell arrays using the
575 @code{num2cell} and @code{mat2cell} functions. 573 @code{num2cell} and @code{mat2cell} functions.
576 574
577 @DOCSTRING(cell) 575 @DOCSTRING(cell)
578 576
649 use cell arrays to store multiple strings. If, however, the character 647 use cell arrays to store multiple strings. If, however, the character
650 matrix representation is required for an operation, it can be converted 648 matrix representation is required for an operation, it can be converted
651 to a cell array of strings using the @code{cellstr} function 649 to a cell array of strings using the @code{cellstr} function
652 650
653 @example 651 @example
652 @group
654 a = ["hello"; "world"]; 653 a = ["hello"; "world"];
655 c = cellstr (a) 654 c = cellstr (a)
656 @result{} c = 655 @result{} c =
657 @{ 656 @{
658 [1,1] = hello 657 [1,1] = hello
659 [2,1] = world 658 [2,1] = world
660 @} 659 @}
660 @end group
661 @end example 661 @end example
662 662
663 One further advantage of using cell arrays to store multiple strings is 663 One further advantage of using cell arrays to store multiple strings is
664 that most functions for string manipulations included with Octave 664 that most functions for string manipulations included with Octave
665 support this representation. As an example, it is possible to compare 665 support this representation. As an example, it is possible to compare
667 the arguments to this function is a string and the other is a cell array 667 the arguments to this function is a string and the other is a cell array
668 of strings, each element of the cell array will be compared the string 668 of strings, each element of the cell array will be compared the string
669 argument, 669 argument,
670 670
671 @example 671 @example
672 @group
672 c = @{"hello", "world"@}; 673 c = @{"hello", "world"@};
673 strcmp ("hello", c) 674 strcmp ("hello", c)
674 @result{} ans = 675 @result{} ans =
675 1 0 676 1 0
677 @end group
676 @end example 678 @end example
677 679
678 @noindent 680 @noindent
679 The following functions for string manipulation support cell arrays of 681 The following functions for string manipulation support cell arrays of
680 strings, @code{strcmp}, @code{strcmpi}, @code{strncmp}, @code{strncmpi}, 682 strings, @code{strcmp}, @code{strcmpi}, @code{strncmp}, @code{strncmpi},
740 can be concatenated into a new column vector containing the elements, by 742 can be concatenated into a new column vector containing the elements, by
741 surrounding the list with @code{[} and @code{]} as in the following 743 surrounding the list with @code{[} and @code{]} as in the following
742 example 744 example
743 745
744 @example 746 @example
747 @group
745 a = @{1, [2, 3], 4@}; 748 a = @{1, [2, 3], 4@};
746 b = [a@{:@}] 749 b = [a@{:@}]
747 @result{} b = 750 @result{} b =
748 1 2 3 4 751 1 2 3 4
752 @end group
749 @end example 753 @end example
750 754
751 It is also possible to pass the accessed elements directly to a 755 It is also possible to pass the accessed elements directly to a
752 function. The list of elements from the cell array will be passed as an 756 function. The list of elements from the cell array will be passed as an
753 argument list to a given function as if it is called with the elements as 757 argument list to a given function as if it is called with the elements as
754 arguments. The two calls to @code{printf} in the following example are 758 arguments. The two calls to @code{printf} in the following example are
755 identical but the latter is simpler and handles more situations 759 identical but the latter is simpler and handles more situations
756 760
757 @example 761 @example
762 @group
758 c = @{"GNU", "Octave", "is", "Free", "Software"@}; 763 c = @{"GNU", "Octave", "is", "Free", "Software"@};
759 printf ("%s ", c@{1@}, c@{2@}, c@{3@}, c@{4@}, c@{5@}); 764 printf ("%s ", c@{1@}, c@{2@}, c@{3@}, c@{4@}, c@{5@});
760 @print{} GNU Octave is Free Software 765 @print{} GNU Octave is Free Software
761 printf ("%s ", c@{:@}); 766 printf ("%s ", c@{:@});
762 @print{} GNU Octave is Free Software 767 @print{} GNU Octave is Free Software
768 @end group
763 @end example 769 @end example
764 770
765 Just like it is possible to create a numerical array from selected 771 Just like it is possible to create a numerical array from selected
766 elements of a cell array, it is possible to create a new cell array 772 elements of a cell array, it is possible to create a new cell array
767 containing the selected elements. By surrounding the list with 773 containing the selected elements. By surrounding the list with
768 @samp{@{} and @samp{@}} a new cell array will be created, as the 774 @samp{@{} and @samp{@}} a new cell array will be created, as the
769 following example illustrates 775 following example illustrates
770 776
771 @example 777 @example
778 @group
772 a = @{1, rand(2, 2), "three"@}; 779 a = @{1, rand(2, 2), "three"@};
773 b = @{ a@{ [1, 3] @} @} 780 b = @{ a@{ [1, 3] @} @}
774 @result{} b = 781 @result{} b =
775 @{ 782 @{
776 [1,1] = 1 783 [1,1] = 1
777 [1,2] = three 784 [1,2] = three
778 @} 785 @}
786 @end group
779 @end example 787 @end example
780 788
781 @noindent 789 @noindent
782 This syntax is however a bit cumbersome, and since this is a common 790 This syntax is however a bit cumbersome, and since this is a common
783 operation, it is possible to achieve the same using the @samp{(} 791 operation, it is possible to achieve the same using the @samp{(}
785 using the @samp{(} and @samp{)} operators a new cell array containing 793 using the @samp{(} and @samp{)} operators a new cell array containing
786 the selected elements will be created. Using this syntax, the previous 794 the selected elements will be created. Using this syntax, the previous
787 example can be simplified into the following 795 example can be simplified into the following
788 796
789 @example 797 @example
798 @group
790 a = @{1, rand(2, 2), "three"@}; 799 a = @{1, rand(2, 2), "three"@};
791 b = a( [1, 3] ) 800 b = a( [1, 3] )
792 @result{} b = 801 @result{} b =
793 @{ 802 @{
794 [1,1] = 1 803 [1,1] = 1
795 [1,2] = three 804 [1,2] = three
796 @} 805 @}
806 @end group
797 @end example 807 @end example
798 808
799 A comma separated list can equally appear on the left-hand side of an 809 A comma separated list can equally appear on the left-hand side of an
800 assignment. An example is 810 assignment. An example is
801 811