Code covered by the BSD License  

Highlights from
Struct array conversion

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 27.85 KB File ID: #27121

Struct array conversion

by Ged Ridgway

 

30 Mar 2010

Convert in either direction between struct-array and structure of arrays

| Watch this File

File Information
Description

Usage: new = struct2struct(old)

If 'old' is a scalar struct containing arrays (each with the same number of rows, N) then 'new' will be an N-by-1 struct-array whose fields have a single row.

If 'old' is an N-by-1 struct-array whose fields have a single row (e.g. as returned above) then 'new' will be a scalar structure whose fields have N rows.

Either representation can have advantages for representing basic spreadsheet or database information.

A struct of arrays allows fields to be added and removed more easily and eases computation of filtering or sorting indices.
(A struct of arrays is also the format returned from csv2struct.)

A struct-array makes it easier to apply filtering and sorting operations using the computed indices/indicators.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
csv2struct

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
struct Ged Ridgway 31 Mar 2010 10:39:02
database Ged Ridgway 31 Mar 2010 10:39:02
spreadsheet Ged Ridgway 31 Mar 2010 10:39:02

Contact us at files@mathworks.com