how preallocate structure for better memory
이전 댓글 표시
I had created a structure made so:
head.number = 3;
head.pck_rcv = [1 0 0];
heads(2).number = 5;
head(2).pck_rcv = [1 1 0];
and so on.
How can I preallocate a structure?
채택된 답변
추가 답변 (2개)
Azzi Abdelmalek
2012년 9월 22일
편집: Azzi Abdelmalek
2012년 9월 22일
heads=struct('numbers',zeros(10,1), 'pck_rcv',zeros(10,3))
%then
for k=1:n
heads.numbers(k)=2
heads.pck_rcv(k,:)=[1 2 3]
end
댓글 수: 3
Alexandra Simpson
2017년 10월 2일
This should be the top answer IMO :)
Jan
2017년 10월 2일
@Alexandra: I do not agree. Salvatore asked for a struct array: "head(2).numbers and so on". Azzi's suggestion creates a scalar struct only.
Alexandra Simpson
2017년 10월 2일
True, I just tried it out and realised it wasn't what I wanted either! Thanks for the response.
Walter Roberson
2012년 12월 13일
head = struct('number', {3, 5}, 'pck_rcv', {[1 0 0], [1 0 1]})
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!