|
|
assign vector accross a vector of structures
Lets say I have a vector struct
a(1).x = 1
a(1).y = 'a'
a(2).x = 2
a(2).y = 'b'
v = [10, 11]
what i want to do is:
a.x = v
how can this be done?
|
|
0
|
|
|
|
Reply
|
Peter
|
1/6/2011 3:46:20 PM |
|
"Peter" wrote in message <ig4o4c$1jh$1@fred.mathworks.com>...
>
> what i want to do is:
> a.x = v
>
Which means what? Do you mean a(i).x=v or instead a(i).x=v(i) for all i?
The former:
[a.x]=deal(v);
The latter:
v=num2cell(v);
[a.x]=deal(v{:});
The latter, splitting vector data across structure array fields, is generally a dubious thing to do, however. It makes data access much slower.
|
|
0
|
|
|
|
Reply
|
Matt
|
1/6/2011 4:00:09 PM
|
|
I meant:
a(i).x=v(i) for all i
why is it a dubious thing to do?
|
|
0
|
|
|
|
Reply
|
Peter
|
1/6/2011 4:10:18 PM
|
|
"Peter" wrote in message <ig4pha$5hf$1@fred.mathworks.com>...
> I meant:
> a(i).x=v(i) for all i
>
> why is it a dubious thing to do?
Well, the data v(i) is stored contiguously in memory whereas the data data a(i).x is not.
That means that the data as it resides in v can be accessed/manipulated much faster. This probably wouldn't be a big deal unless length(v) is really large...
|
|
0
|
|
|
|
Reply
|
Matt
|
1/6/2011 4:33:04 PM
|
|
"Matt J" wrote in message <ig4qs0$5v1$1@fred.mathworks.com>...
> "Peter" wrote in message <ig4pha$5hf$1@fred.mathworks.com>...
> > I meant:
> > a(i).x=v(i) for all i
> >
> > why is it a dubious thing to do?
>
> Well, the data v(i) is stored contiguously in memory whereas the data data a(i).x is not.
> That means that the data as it resides in v can be accessed/manipulated much faster. This probably wouldn't be a big deal unless length(v) is really large...
Interesting. Thanks a lot
|
|
0
|
|
|
|
Reply
|
Peter
|
1/7/2011 7:12:05 AM
|
|
|
4 Replies
265 Views
(page loaded in 0.06 seconds)
Similiar Articles: Assigning value to symbolic expressions in vector - comp.soft-sys ...... In the meanwhile, if you have the symbolic toolbox ... code or help me how to ... operate on a vector of values for ... assign vector accross a vector of structures ... What do "event_reach" messages mean? - comp.protocols.time.ntp ...assign vector accross a vector of structures - comp.soft-sys ... "Peter" wrote in message <ig4o4c$1jh$1@fred.mathworks.com>... > > what i want to do is: > a.x = v > Which ... splitting a sequence of arrays - comp.lang.awkQuestion about awk variable assignment - comp.lang.awk assign vector accross a vector of structures - comp.soft-sys ..... correctly, the std::vector functions ... or ... does vector::resize throw bad_alloc exception? - comp.lang.c++ ...resize array - comp.soft-sys.matlab How to increment vector/array?? - comp.soft-sys.matlab assign vector accross a ... does vector::resize throw bad_alloc exception ... Assigning same value to multiple variables - comp.lang.rexx ...How to assign a variable name to a structure? - comp.soft-sys ... Structure Variables To assign and ... Assigning value to symbolic expressions in vector - comp.soft-sys ... ... how to assign part numbers to screws from toolbox? - comp.cad ...... them in the BOM for the assembly, how can I assign ... ... The closest swx tool for this task I came across was ... Remove structure - comp.soft-sys.matlab In my case, I don't ... map of string to ostringstream - comp.lang.c++.moderated ...Background: Essentially, I've got an array of C structures ... For the second traversal, I use a vector of map ... char> which has a private copy constructor and assignment ... Diff a struct - comp.soft-sys.matlabI have a several structures with dozens of fields, b... ... in term of x... - comp.soft-sys.matlab If X is a vector ... variable can be assigned null.But we cannot assign ... Y axis plot labeling? Want auto scaling, but want to format ...... from all the values, and choose a number of ticks (5 in this case), and assign ... All the above worked, and I have learned more about Matlab cells and vector structures ... comp.lang.c++.moderated - page 175In paritcular I create a vector of sets and insert ... Object Assignment 2 100 (7/26/2004 10:48:42 PM) Example #1 ... I've defined a structure like this typedef struct myA ... Trying to make a vector of structures, need help - GIDForumsTrying to make a vector of structures, need help ... cannot figure out is how to assign the values from the newvect vector into a vector that is a member of a group structure ... Sequence container (C++) - Wikipedia, the free encyclopediaThe vector data structure is able to quickly and easily allocate the necessary memory ... vector, subsequent elements are moved backwards in terms of their assignment ... 7/13/2012 10:51:47 PM
|
|
|
|
|
|
|
|
|