From: Pavitra on
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
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().