add a new field to structure

조회 수: 479(최근 30일)
Majid Al-Sirafi
Majid Al-Sirafi 2013년 12월 4일
편집: Stephen23 2017년 12월 19일
Hi all friends
I have a structure variable; this variable is defined as follows:
Student structure; consists of the following fields
Suppose that I fill it with data (for example five students)
Later I want to add another field (for example degree field) to student structure
How can I do that and fill the degree field with data
Please help me

채택된 답변

Wayne King
Wayne King 2013년 12월 4일
편집: Wayne King 2013년 12월 4일
teststruct = struct('names',{'bob','dave','sara'});
% now add field called data
[teststruct(:).data] = deal(randn(3,1));
  댓글 수: 2
Stephen23 2017년 12월 19일
C = num2cell(randn(3,1));
[teststruct(:).data] = deal(C{:})
How this works is explained in the MATLAB documentation:

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Majid Al-Sirafi
Majid Al-Sirafi 2013년 12월 4일
thank you sir, that is I want
best regards



Community Treasure Hunt

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

Start Hunting!

Translated by