Code covered by the BSD License  

Highlights from
repositionStructField

Be the first to rate this file! 1 Download (last 30 days) File Size: 1.34 KB File ID: #32275

repositionStructField

by Georg D

 

20 Jul 2011

a bit more convenient way to reposition fields in a structure

| Watch this File

File Information
Description

function [s] = repositionStructField(s,shiftfield,newpos)
%shiftfield can be fieldname (string) or current position index of field
%newpos can be either new position index of field, or the name of the field (as string) that is
%currently occupying the new position

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
field, orderfields, struct
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
21 Jul 2011 Georg D

i can change the field order in
s = struct('a',val1,'b',val2,'c',val3)
to
s = struct('a',val1,'c',val3,'b',val2)
by
s = repositionStructField(s,'c','b')
or
s = repositionStructField(s,3,2)

it just uses orderfields, but is sometimes a bit more convenient to shift positions of single fields...

21 Jul 2011 Jan Simon

In which situation do you use this function?

Contact us