|
Prev: SimEvents randomising generator block seed in an model executable
Next: Wholesale all kinds of cheap Nike, puma, Adidas shoes
From: Pavitra on 25 Jul 2010 22:37 I have a 200x200 struct array S with multiple fields. One of the fields, S.pops contains a 10x2 array that tracks the population (in column 2) of the types with numerical IDs (column 1) at a particular site on the grid. For example it could be [1,10; 2,0; 5,1;...] and so on. Say I need to increment the population of only type 1s at selected locations on the grid. Is there a way to do this without a for loop that goes over the entire grid? If the locations I want to update are in an array locs (with their linear indexes), I want to do something like [S(locs).pops(1,2)]=[S(locs).pops(1,1)]+1; but I get the error: "??? Scalar index required for this type of multi-level indexing." Any ideas?
From: Walter Roberson on 25 Jul 2010 22:42
Pavitra wrote: > I have a 200x200 struct array S with multiple fields. One of the fields, > S.pops contains a 10x2 array that tracks the population (in column 2) of > the types with numerical IDs (column 1) at a particular site on the > grid. For example it could be [1,10; 2,0; 5,1;...] and so on. > > Say I need to increment the population of only type 1s at selected > locations on the grid. Is there a way to do this without a for loop that > goes over the entire grid? Either a "for" loop or the equivalent such as arrayfun(). |