annotate toolboxes/FullBNT-1.0.7/docs/cellarray.html @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 Cell arrays are a little tricky in Matlab.
Daniel@0 2 Consider this example.
Daniel@0 3
Daniel@0 4 C=num2cell(rand(2,3))
Daniel@0 5 C =
Daniel@0 6 [0.4565] [0.8214] [0.6154]
Daniel@0 7 [0.0185] [0.4447] [0.7919]
Daniel@0 8
Daniel@0 9 C{1,2} % this is the contents of this cell (could be a vector or a string)
Daniel@0 10 ans =
Daniel@0 11 0.8214
Daniel@0 12
Daniel@0 13 C{1:2,2} % this is the contents of these cells - returns multiple
Daniel@0 14 answers!
Daniel@0 15 ans =
Daniel@0 16 0.8214
Daniel@0 17 ans =
Daniel@0 18 0.4447
Daniel@0 19
Daniel@0 20 A = C(1:2,2) % this is a slice of the cell array
Daniel@0 21 ans =
Daniel@0 22 [0.8214]
Daniel@0 23 [0.4447]
Daniel@0 24
Daniel@0 25 A{1} % A is itself a cell array
Daniel@0 26 ans =
Daniel@0 27 0.8214
Daniel@0 28
Daniel@0 29
Daniel@0 30
Daniel@0 31 >> C(1:2,2)=0 % can't assign a scalar to a cell array
Daniel@0 32 C(1:2,2)=0
Daniel@0 33 ??? Conversion to cell from double is not possible.
Daniel@0 34
Daniel@0 35
Daniel@0 36 >> C(1:2,2)={0;0} % can assign a cell array to a cell array
Daniel@0 37 C(1:2,2)={0;0}
Daniel@0 38 C =
Daniel@0 39 [0.4565] [0] [0.6154]
Daniel@0 40 [0.0185] [0] [0.7919]
Daniel@0 41
Daniel@0 42
Daniel@0 43 BTW, I use cell arrays for evidence for 2 reasons:
Daniel@0 44
Daniel@0 45 1. [] indicates missing values
Daniel@0 46 2. it can easily represent vector-valued nodes
Daniel@0 47
Daniel@0 48 The following example makes this clear
Daniel@0 49
Daniel@0 50 C{1,1} = []
Daniel@0 51 C{2,1} = rand(3,1)
Daniel@0 52
Daniel@0 53 C =
Daniel@0 54 [] [0] [0.6154]
Daniel@0 55 [3x1 double] [0] [0.7919]
Daniel@0 56
Daniel@0 57
Daniel@0 58 Hope this helps,
Daniel@0 59 Kevin