0

I have a large structure array.

I would like to perform a sensitivity analysis on a function that processes this array.

So, say my structure array has name 's', 10,000 elements, and field names 'x' and 'y'.

I'd like to do the following:

xs = [s(:).x];
xs = xs + 5*randn(size(xs));
s(:).x = xs;

Sadly, the last step is not valid matlab. Any thoughts? Was hoping to avoid a loop.

John
  • 5,735
  • 3
  • 46
  • 62
  • 3
    Please refer to: [Updating one field in every element of a Matlab struct array](http://stackoverflow.com/questions/9303070/updating-one-field-in-every-element-of-a-matlab-struct-array) – p8me May 23 '13 at 23:09
  • I suspect the problem is that even if Matlab **could** handle an expression like that, it's not clear whether each array element `s(i).x` should contain the entirety of `xs` or just a single element from `xs` – Ryan J. Smith May 23 '13 at 23:17

1 Answers1

0

From this answer and after playing around with deal. I think I have what you are looking for but it requires converting xs into a cell array using num2cell:

xs_cell = num2cell(xs); % convert matrix to cell array.
[S(:).X]=xs_cell{:}; % update the values in the field X
Community
  • 1
  • 1
Azim J
  • 8,260
  • 7
  • 38
  • 61