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.

2
  • 3
    Please refer to: Updating one field in every element of a Matlab struct array Commented May 23, 2013 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 Commented May 23, 2013 at 23:17

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.