Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Let's use the information gleaned from this page to create our structure using the struct function. The help says that the format for using the struct function is

strArray = struct('field1',val1,'field2',val2, ...)

Bring up the editor by clicking on the New M-file icon (or any other preferred way). Copy the above struct statement into the M-file and modify it to create the sigepstruct structure.

sigepsstruct = struct('eps', eps_val, ...
                     'sig', sig_val);

We use "..." to start a new line. In order for this to work, we, of course, need to allocate strain and stress values to eps_val and sig_val, respectively, abovethis statement. We'll use dummy values that would horrify any self-respecting solid mechanics professor. We do so in order to make the programming aspects easier to understand.

Wiki Markup
_{{%Testing the use of structure_}}
_{{clear all; %Clear all variables from workspace_}}
_{{eps_val = \[2 7 4\];%Nonsense   values_}}
_{{R = 2*eye(3); %Dummy R_}}
_{{sig_val = (R*eps_val')';%Derived nonsense_}}

In your actual redAnTS implementation, the strains will be derived from the displacements that redAnTS provides from inversion of the stiffness matrix. And you'd have a meaningful R matrix. Note that we specify eps_val as a row vector; we have to use the transpose operator (') to ensure we end up with a row vector for sig_val also.

...

We have now created our structure. Let's now see how we can extract parts of the structure. Since you are a real woman/man, go back to the above help page and read the section on Accessing Data in Structure Arrays. It tells you that to access a field of a particular structure, include a period (.) after the structure name followed by the field name. Use this to extract the entire stress vector and, say, the second item in the eps field (which is εyy).

%Extract data from structure
sigepsstruct.sig %Extract the stress vector
sigepsstruct.eps(2)%Extract the 2nd element of eps

Check in the command window that the correct values are extracted.

...