From: George on 14 Jun 2010 21:01 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hutq6d$f0v$1(a)fred.mathworks.com>... > "George " <guanjihou(a)gmail.com> wrote in message <hutpgd$km$1(a)fred.mathworks.com>... > > Hi guys, > > > > I have a question dealing with arrays. Here it go: > > > > Suppose A is a 3 by 1 array, I want to assign A (1,1) a 5 by 1 array B, can I do this? How? > > > > Thanks in advance! > > Hi George, make A a cell array > > A = cell(3,1); > B = randn(5,1); > A{1} = B; > > Wayne Hi, I have one more confusing about this. What I want to is to create a structure that contains cell and other variable, then assign values to the cell according to inputs. But according the Matlab Help, it says that 'If any of the values fields is an empty cell array {}, MATLAB creates an empty structure array in which all fields are also empty.' So I can't assign values to this 'empty' cell, how can I solve this problem? For example: s=struct ( 'A', 0,... 'B',[],... ) s.A=100; s.B=[2,1]; % there is no problem of doing this p=struct ( 'C',{},... ) p.C=cell (1,3); % There is not ok to do this, with the following error: A dot name structure assignment is illegal when the structure is empty. Use a subscript on the structure. Can someone help me out of this? Thanks in advance!
From: us on 14 Jun 2010 21:12 "George " > p=struct ( > 'C',{},... > ) > p.C=cell (1,3); > % There is not ok to do this, with the following error: > > A dot name structure assignment is illegal when the structure is empty. > Use a subscript on the structure. > > Can someone help me out of this? > > Thanks in advance! well... yes... it's crystal clear... isn't it(?)... you MUST your create your field .C as non-empty... us
From: George on 14 Jun 2010 21:18 "us " <us(a)neurol.unizh.ch> wrote in message <hv6k14$qe3$1(a)fred.mathworks.com>... > "George " > > p=struct ( > > 'C',{},... > > ) > > p.C=cell (1,3); > > % There is not ok to do this, with the following error: > > > > A dot name structure assignment is illegal when the structure is empty. > > Use a subscript on the structure. > > > > Can someone help me out of this? > > > > Thanks in advance! > > well... yes... > it's crystal clear... isn't it(?)... > you MUST your create your field .C as non-empty... > > us But at initialization stage, I just want to define a structure with a cell in it. I don't know about the size until the input comes in. There is a normal programing process, can Matlab handle this by some method? thanks!
From: Walter Roberson on 14 Jun 2010 21:29 George wrote: > But at initialization stage, I just want to define a structure with a > cell in it. I don't know about the size until the input comes in. There > is a normal programing process, can Matlab handle this by some method? p = struct('C', {{}}); This is explicitly described in the struct documentation.
From: George on 14 Jun 2010 21:53 Walter Roberson <roberson(a)hushmail.com> wrote in message <oIARn.72893$Gx2.54158(a)newsfe20.iad>... > George wrote: > > > But at initialization stage, I just want to define a structure with a > > cell in it. I don't know about the size until the input comes in. There > > is a normal programing process, can Matlab handle this by some method? > > p = struct('C', {{}}); > > This is explicitly described in the struct documentation. Yes, this is it. Thanks very much, Mr. Roberson. I really appreciate.
First
|
Prev
|
Pages: 1 2 Prev: Importing from Excel - storing each sheet as a separate variable Next: Use of isprop |