1

I have a structure with sample being a numeric vector. I would like to replace the numbers in sample by sample/2. However, I do not know how to overcome the following error:

Scalar structure required for this assignment.

Any suggestions are more than welcome.

Example:

field1 = 'event';
value1 = {'A', 'B', 'C', 'D'};
field2 = 'sample';
value2 = 22;

A = struct(field1, value1, field2, value2);

What I want to do:

A.sample = round([A.sample]/2,0);
m7913d
  • 10,244
  • 7
  • 28
  • 56
Christine Blume
  • 507
  • 3
  • 7
  • 17

1 Answers1

0

You should use the deal function to distribute your calculated matrix to the elements of your structure:

sampleCell = num2cell(round([A.sample]/2,0)); % first convert result to cell, to comply with the `deal` syntax
[A.sample] = deal(sampleCell{:});
m7913d
  • 10,244
  • 7
  • 28
  • 56