About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
  • Last update: 5 years ago
  • Total downloads: 43
  • Operating system: Linux, Mac OS X, Win All, BSD, Solaris
  • Publisher: Matt J (15 other programs)
See full specifications

scripts default iconStructure Fields To Variables (Scripts) Publisher's description

Structures are a convenient way of carrying around many

Structures are a convenient way of carrying around many variables as a single object and of passing those variables to a function packed in a single argument.

Once a structure has been passed to a function, however, many users (according to various Newsgroup posts) find it tiresome to have to access its fields repeatedly through dot-indexing notation and have sought automated ways to take a structure and assign all of its fields to separate variables, as in

a = myStruct.a;
b = myStruct.b;
c = myStruct.c;

Solutions based on assignin() have often been tried, but are hazardous, for reasons discussed, for example, in this thread:


The structvars() tool in this FEX submission does something virtually as good and far safer.

Given a structure, it will print a set of assignment commands that, if executed, would assign fields of a structure to individual variables of the same name (or vice versa). The expression produced by structvars() can be conveniently copy/pasted from the command window to the file editor at the location in the file where the variables need to be unpacked.

Examples: Given structure myStruct, with fields a,b,c, & d

(1) structvars(myStruct) %assign fields to variables

ans =

a = myStruct.a;
b = myStruct.b;
c = myStruct.c;
d = myStruct.d;

(2) structvars(3,myStruct) %split the last result across 3 columns

ans =

a = myStruct.a; c = myStruct.c; d = myStruct.d;
b = myStruct.b;

(3) structvars(3,myStruct,0) %assign variables to fields

ans =

myStruct.a = a; myStruct.c = c; myStruct.d = d;
myStruct.b = b;

The commands can obviously be regenerated if you add/remove structure fields later on. On the other hand, the effort of just making these incremental edits manually is typically minimal.

System Requirements:

MATLAB 7.9 (2009b)
Program Release Status: Major Update
Program Install Support: Install and Uninstall

Structure Fields To Variables (Scripts) Tags:

Click on a tag to find related softwares

Is Structure Fields To Variables (Scripts) your software?

Manage your software

Most Popular

scripts default icon ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation 1.1
ASK, OOK, FSK, BPSK, QPSK, 8PSK modulation contain several functions for digital modulation simulation
scripts default icon Simulink Communication Labs 1.1
Simulink Communication Labs allows you to learn communication systems in greater depth.
scripts default icon M-QAM modulation and demodulation 1.1
M-QAM modulation and demodulation is the QAM modulation and demodulation tech.
scripts default icon LZW Compression/Decompression 1.1
LZW Compression/Decompression - Updated LZW compressor and decompressor with reasonable performance
scripts default icon InSPIRE utility to plot a 2D displacement field (Scripts) 1.0
This program plots the deformation field (displace vectors) contained in vector.txt.