Structures


Structure is a user-defined data type which consists of a bunch of variables -- see picture below:

 

 


 

 

Here's how you'd create a structure in MATLAB:

» Case.Name = 'Jack';
» Case.ID = '123456';
» Case.Status = 'Open-Pending Research';

» Case

Case =
Name: 'Jack'
ID: '123456'
Status: 'Open-Pending Research'

» whos

Name Size Bytes Class

Case 1x1 434 struct array

Grand total is 34 elements using 434 bytes
»

 

Here's how you'd do it in C:
#include struct Case { char Name[100]; int CaseID; char CaseStatus[100]; }; void main( ) { char *dummyname = {"Jack"}; int dummyid = 123456; char *dummystatus = {"Open-Pending Research"}; struct Case *MyCase; MyCase = (struct Case *)malloc(sizeof(struct Case)); strcpy(MyCase->Name, dummyname); MyCase->CaseID = dummyid; strcpy(MyCase->CaseStatus, dummystatus); printf("Contact Name: %s\n", MyCase->Name); printf("Case ID : %d\n", MyCase->CaseID); printf("Case Status : %s\n", MyCase->CaseStatus); free(MyCase); }

Let's take a closer look at the above C-code