[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Removing disadvantages on struct array and cell struct array?
From: |
veryhappy |
Subject: |
Re: Removing disadvantages on struct array and cell struct array? |
Date: |
Sun, 9 Jan 2011 12:04:40 -0800 (PST) |
I knew about struct_levels_to_print but for some reason that i can't
understand struct arrays only show the name of the fields (they show the
full information if you specify a concrete element of the array) :S
Thanks for your reply i'll try to make it clearer giving you an example.
If execute a script with the following content:
% Struct array example
clear circuit
struct_levels_to_print(10);
component(1)=struct("type",'r',"value",1e4);
component(2)=struct("type",'c',"value",1e-7);
component(3)=struct("type",'r',"value",2.2e3);
component
circuit(1).component=component;
circuit(2).component=component;
circuit
I get the next results:
component =
{
1x3 struct array containing the fields:
type
value
}
circuit =
{
1x2 struct array containing the fields:
component
}
As you see i don't get the contents of the struct but using struct arrays i
can do things like
[circuit(1).component.print_value]={'10K','100nF','2K2'}{:}. I would like to
retain that functionality and get something like:
circuit =
{
[1] =
{
component =
{
[1] =
{
type = r
value = 10000
}
[2] =
{
type = c
value = 1.0000e-007
}
[3] =
{
type = r
value = 2200
}
}
}
[2] =
{
component =
{
[1] =
{
type = r
value = 10000
}
[2] =
{
type = c
value = 1.0000e-007
}
[3] =
{
type = r
value = 2200
}
}
}
}
On the other hand if i use cell struct arrays like in the next script:
% Cell struct array example
clear circuit
struct_levels_to_print(10);
component(1)=struct("type",'r',"value",1e4);
component(2)=struct("type",'c',"value",1e-7);
component(3)=struct("type",'r',"value",2.2e3);
component
circuit{1}.component=num2cell(component);
circuit{2}.component=num2cell(component);
circuit
I get the full information:
component =
{
1x3 struct array containing the fields:
type
value
}
circuit =
{
[1,1] =
{
component =
{
[1,1] =
{
type = r
value = 10000
}
[1,2] =
{
type = c
value = 1.0000e-007
}
[1,3] =
{
type = r
value = 2200
}
}
}
[1,2] =
{
component =
{
[1,1] =
{
type = r
value = 10000
}
[1,2] =
{
type = c
value = 1.0000e-007
}
[1,3] =
{
type = r
value = 2200
}
}
}
}
But i can't do simple things like circuit(1).component without using cellfun
and, perhaps, auxiliary functions (i would write the previous statment like:
cellfun(@(x) x.component,circuit(1),"UniformOutput",false)). There may be an
easier way but i don't know how
I hope all this had helped you understand what i'm asking for.
Thanks in advance
--
View this message in context:
http://octave.1599824.n4.nabble.com/Removing-disadvantages-on-struct-array-and-cell-struct-array-tp3204898p3206264.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Removing disadvantages on struct array and cell struct array?, veryhappy, 2011/01/08
- Re: Removing disadvantages on struct array and cell struct array?, Olaf Till, 2011/01/08
- Re: Removing disadvantages on struct array and cell struct array?, veryhappy, 2011/01/09
- Re: Removing disadvantages on struct array and cell struct array?, John W. Eaton, 2011/01/09
- Re: Removing disadvantages on struct array and cell struct array?,
veryhappy <=
- Re: Removing disadvantages on struct array and cell struct array?, John W. Eaton, 2011/01/09
- Re: Removing disadvantages on struct array and cell struct array?, Olaf Till, 2011/01/10
- Re: Removing disadvantages on struct array and cell struct array?, Sergei Steshenko, 2011/01/10
- Re: Removing disadvantages on struct array and cell struct array?, John W. Eaton, 2011/01/10
- Re: Removing disadvantages on struct array and cell struct array?, veryhappy, 2011/01/10
- Re: Removing disadvantages on struct array and cell struct array?, John W. Eaton, 2011/01/10