MATLAB: Add a new array to a strucure

structures

A simple and quick question.
I have a structure A and I want to add a new array to it and the array is
X = [365 322 481 727 914 605 785 313 806 821]
I tried this
A(i).Rim = X';
But it puts all the numbers in the last row of the structure, and i want to put one number in each row. What should i do, any suggestion?

Best Answer

Taking a guess that you have a non-scalar structure and that you want to allocate new data to the same field of each element of the structure, then this is trivial using a comma-separated list:
>> X = [365,322,481,727,914,605,785,313,806,821];
>> C = num2cell(X);
>> A = struct('Z',num2cell(1:numel(X))'); % fake structure
>> [A.Rim] = C{:};
You can also use indexing to allocate to the correct elements of A.