Create a 1 x m Structure instead of a 1x1 Structure
26 次查看(过去 30 天)
显示 更早的评论
Hello,
Im tring to create a 1 x m structure instead of a 1x1. When doing the following, it creates a 1x1 struct
MySturcture.FirstField = [1:100]
MySturcture.SecondField = [1:100]
I would like to open the struct to the fields being side by side (1x2 structure), displaying all of the data, similar to the image in this question.
[FirstField] [SecondField]
1 1
2 2
3 3
etc.. etc..
Any help would be greatly appreciated.
0 个评论
采纳的回答
更多回答(2 个)
Ameer Hamza
2020-5-8
编辑:Ameer Hamza
2020-5-8
This is one of the way.
MySturcture(100).FirstField = [];
MySturcture(100).SecondField = [];
A = num2cell(1:100);
[MySturcture.FirstField] = A{:};
[MySturcture.SecondField] = A{:};
Steven Lord
2020-5-8
Your second design looks less like a struct and more like a table.
x = (0:11).';
y = x.^2;
t = table(x, y)
If you wanted a new "field" (table variable) you can add them, using variables from the table and/or variables from the workspace as desired.
t.z = t.y - t.x/2
t.w = sinpi(x./4)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!