Add a new array to a strucure

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?

 采纳的回答

Stephen23
Stephen23 2017-5-24
编辑:Stephen23 2017-5-24
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.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by