comparison toolboxes/FullBNT-1.0.7/docs/cellarray.html @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 Cell arrays are a little tricky in Matlab.
2 Consider this example.
3
4 C=num2cell(rand(2,3))
5 C =
6 [0.4565] [0.8214] [0.6154]
7 [0.0185] [0.4447] [0.7919]
8
9 C{1,2} % this is the contents of this cell (could be a vector or a string)
10 ans =
11 0.8214
12
13 C{1:2,2} % this is the contents of these cells - returns multiple
14 answers!
15 ans =
16 0.8214
17 ans =
18 0.4447
19
20 A = C(1:2,2) % this is a slice of the cell array
21 ans =
22 [0.8214]
23 [0.4447]
24
25 A{1} % A is itself a cell array
26 ans =
27 0.8214
28
29
30
31 >> C(1:2,2)=0 % can't assign a scalar to a cell array
32 C(1:2,2)=0
33 ??? Conversion to cell from double is not possible.
34
35
36 >> C(1:2,2)={0;0} % can assign a cell array to a cell array
37 C(1:2,2)={0;0}
38 C =
39 [0.4565] [0] [0.6154]
40 [0.0185] [0] [0.7919]
41
42
43 BTW, I use cell arrays for evidence for 2 reasons:
44
45 1. [] indicates missing values
46 2. it can easily represent vector-valued nodes
47
48 The following example makes this clear
49
50 C{1,1} = []
51 C{2,1} = rand(3,1)
52
53 C =
54 [] [0] [0.6154]
55 [3x1 double] [0] [0.7919]
56
57
58 Hope this helps,
59 Kevin