From: megha bhatt on
Hello,
I have a structure with fields name written in capital letters. I want to change the names in small letters because I want to use this structure often in my program and to switch between capital and small letters is not very feasible.
suppose the structure is given as below:

sr.VMON5D, sr.ERRORID, sr.VMON1D, sr.VMON3D, sr.VMON5A, sr.CMON5D
I want to change it as below:
sr.vmon5d , sr.errorid , sr.vmon1d, sr.vmon3D, sr. vmon5a, sr.cmon5d

I tried like this :
test=strctfun(@(x) (lower(fieldnames(x))), sr, 'UniformOutput', false);

I am getting error msg:
??? Undefined function or method 'fieldnames'
for input arguments of type 'cell'

Then I tried in another way:
test =structfun(@(x) lower(char(fieldnames(sr))),sr, 'UniformOutput', false);

and again I am getting the same error.

Can you please let me know the correct way to change the case of field names of a structure?
Thanks,
Megha
From: Matt J on
"megha bhatt" <mubhatt19(a)yahoo.co.in> wrote in message <hntid9$iq1$1(a)fred.mathworks.com>...
> Hello,
> I have a structure with fields name written in capital letters. I want to change the names in small letters because I want to use this structure often in my program and to switch between capital and small letters is not very feasible.
> suppose the structure is given as below:
>
> sr.VMON5D, sr.ERRORID, sr.VMON1D, sr.VMON3D, sr.VMON5A, sr.CMON5D
> I want to change it as below:
> sr.vmon5d , sr.errorid , sr.vmon1d, sr.vmon3D, sr. vmon5a, sr.cmon5d

fn=filednames(sr);

for ii=1:length(fn)

fname=fn{ii};
sr_new.(lower(fname))=sr.(fname);

end