MATLAB: Multiply each element of structured array, assignment of structured array

structure

I'm not exactly sure if I'm using the right terminology. I have
A(1).B = 5;
A(2).B = 6;
A(3).B = 7;
>>A.B
ans =
5
ans =
6
ans =
7
I have two questions: 1. I want to multiply each element of the structured array so that A.B*2 would equal 10,12,14 instead of 5,6,7. but instead I get the error
>>A.B*2
Error using *
Too many input arguments.
2. How do I make a copy of the structured array? I have tried but it just results in the first element.
>>C = A.B
C =
5
Likewise
>> C = A(1:3).B
C =
5
instead of C(1).B = 5, C(2).B = 6, and C(3).B = 7 like I want.

Best Answer

The short answer is NO, it is not possible. However, ...
>> [A.B] = split( 2*[A.B] )
A =
1x3 struct array with fields:
B
>> A.B
ans =
10
ans =
12
ans =
14
where
function varargout = split( vec )
assert( nargout == numel( vec ) ...
, 'split:narginNargoutMismatch' ...
, 'The number of outputs should match the length of the input vector.')
varargout = num2cell( vec );
end
Related Question