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
See full specifications

scripts default iconmultiLevelStructMat (Scripts) Publisher's description

Suppose you want the values from myStruct(:,:).vec(1) in a matrix the same size as
the struct array myStruct

Suppose you want the values from myStruct(:,:).vec(1) in a matrix the same size as
the struct array myStruct, and myStruct(ii,jj).vec is a number, a vector, or a
matrix for every ii and jj. myStruct can be a struct array of any size. The size of the
field (e.g., vec) does not have to be the same for every element of the struct array.

If you were to naively type myMat = [myStruct(:,:).vec(1)] you would get the error
"Scalar index required for this type of multi-level indexing."

Instead of using for loops to construct the matrix, you can use multiLevelStructMat.
The following two lines are equivalent.
myMat = multiLevelStructMat(myStruct, 'myStruct.vec(1)');
myMat = multiLevelStructMat(myStruct, 'myStruct(:,:).vec(1)');

You can also make a matrix from only part of a structure array.
myMat = multiLevelStructMat(myStruct, 'myStruct(1:2,end).vec(1)')

Suppose myStruct(ii,jj).vec is a 2x1 vector for some ii and jj, and a 3x1 vector for
other ii and jj. The function call shown below will give an error.
myMat = multiLevelStructMat(myStruct, 'myStruct.vec(3)');

However, you can use the optional third argument forceNan to force multiLevelStructMat
to make the matrix, even if, for some elements in the struct array, the desired position
in the field doesn't exist. If you use the forceNan argument as shown below, the matrix
will be constructed, and any values that don't exist in the field of the struct array
will be NaN in the matrix. This will slow down the function by up to a factor of ~2,
depending on how many NaNs must be inserted (if no NaNs, then no slow-down).
myMat = multiLevelStructMat(myStruct, 'myStruct.vec(3)', nan);

Nested structures are not allowed, and will give an error. If your struct array is
inside a structure, you must first create a new variable of only the struct array.
myNewStruct = bigStruct.myStruct;
myMat = multiLevelStructMat(myNewStruct, 'myNewStruct(:,1).vec(1)');

If you call multiLevelStructMat with a string that has non-scalar indices for the field,
but scalar indices for the struct array (something matlab can handle with no problems),
you will get the expected result.
myMat = multiLevelStructMat(myStruct, 'myStruct(1,4).vec(:)');

You can have non-scalar indices for the struct array or for the field, but not both.

For example, if size(myStruct(ii,jj).vec) = [1 1] for all ii and jj, then the following
statements are acceptable and equivalent:
myMat = multiLevelStructMat(myStruct, 'myStruct.vec');
myMat = multiLevelStructMat(myStruct, 'myStruct(:,:).vec');

On the other hand, if size(myStruct) = [1 1], then the following statement is
myMat = multiLevelStructMat(myStruct, 'myStruct.vec');

If however, both the struct array and the field have non-scalar indices, the function
will throw an error:
myMat = multiLevelStructMat(myStruct, 'myStruct(:,1).vec(1:2)');

multiLevelStructMat may be slow for very large struct arrays, as it uses for loops and
makes no assumptions about the size of the field in each element of the struct array.

System Requirements:

MATLAB 7.11 (2010b)
Program Release Status: New Release
Program Install Support: Install and Uninstall

multiLevelStructMat (Scripts) Tags:

Click on a tag to find related softwares

Is multiLevelStructMat (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.