File Exchange

image thumbnail


version (1.34 KB) by Georg D
a bit more convenient way to reposition fields in a structure


Updated 20 Jul 2011

View License

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

Cite As

Georg D (2021). repositionStructField (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

Georg D

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

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


In which situation do you use this function?

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!