Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to manipulate a variable name

Subject: how to manipulate a variable name

From: Adam Chapman

Date: 7 Apr, 2008 19:35:20

Message: 1 of 9

Hello,

I am trying to order some neural networks into ascending accuracy. Now
I want to save the nets in a file so that the most accurate is called
'net1', the second most accurate 'net2' and so on.

Here's some code to describe what im trying to do..

accuracy=rand(1,5)
SORTED=accuracy; % put accuracy into a matrix that can be ordered with
net index
SORTED(2,1:length(accuracy))=1:length(accuracy); % net number or index
SORTED=SORTED';
SORTED=sortrows(SORTED); %sort nets in terms of accuracy
 SORTED=SORTED';

accuracy=SORTED(1,:); %sorted accuracy
nets=SORTED(2,:);


now, for example we might have
nets =

     2 3 1 4 5


so now i want to save the current net2 as net1,
the curent net3 as net2,
the curent net1 as net3, etc

Is this even possible? I've been racking my brains against this one
for a couple of hours

Subject: how to manipulate a variable name

From: Adam Chapman

Date: 7 Apr, 2008 20:06:12

Message: 2 of 9

On Apr 7, 8:35=A0pm, Adam Chapman
<adam.chap...@student.manchester.ac.uk> wrote:
> Hello,
>
> I am trying to order some neural networks into ascending accuracy. Now
> I want to save the nets in a file so that the most accurate is called
> 'net1', the second most accurate 'net2' and so on.
>
> Here's some code to describe what im trying to do..
>
> accuracy=3Drand(1,5)
> SORTED=3Daccuracy; % put accuracy into a matrix that can be ordered with
> net index
> SORTED(2,1:length(accuracy))=3D1:length(accuracy); % net number or index
> SORTED=3DSORTED';
> SORTED=3Dsortrows(SORTED); %sort nets in terms of accuracy
> =A0SORTED=3DSORTED';
>
> accuracy=3DSORTED(1,:); %sorted accuracy
> nets=3DSORTED(2,:);
>
> now, for example we might have
> nets =3D
>
> =A0 =A0 =A02 =A0 =A0 3 =A0 =A0 1 =A0 =A0 4 =A0 =A0 5
>
> so now i want to save the current net2 as net1,
> the curent net3 as net2,
> the curent net1 as net3, etc
>
> Is this even possible? I've been racking my brains against this one
> for a couple of hours

I found a solution for renaming variables:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3D8=
677

Subject: how to manipulate a variable name

From: Jos

Date: 8 Apr, 2008 05:46:01

Message: 3 of 9

Adam Chapman <adam.chapman@student.manchester.ac.uk> wrote
in message
<14732535-a9c0-48ff-bc0a-d5a3230022af@u12g2000prd.googlegroups.com>...
> Hello,
>
> I am trying to order some neural networks into ascending
accuracy. Now
> I want to save the nets in a file so that the most
accurate is called
> 'net1', the second most accurate 'net2' and so on.
>
> Here's some code to describe what im trying to do..
>
> accuracy=rand(1,5)
> SORTED=accuracy; % put accuracy into a matrix that can be
ordered with
> net index
> SORTED(2,1:length(accuracy))=1:length(accuracy); % net
number or index
> SORTED=SORTED';
> SORTED=sortrows(SORTED); %sort nets in terms of accuracy
> SORTED=SORTED';
>
> accuracy=SORTED(1,:); %sorted accuracy
> nets=SORTED(2,:);
>
>
> now, for example we might have
> nets =
>
> 2 3 1 4 5
>
>
> so now i want to save the current net2 as net1,
> the curent net3 as net2,
> the curent net1 as net3, etc
>
> Is this even possible? I've been racking my brains against
this one
> for a couple of hours

Do not setup your variables like this in the first place.
Use cell arrays or rows of matrices. Then shuffling becomes
quite easy!

mynet = {'A','B','C','D','E'} ; % 5 values
nets = [2 3 1 4 5] % new order
mynet = mynet(nets) % shuffled

hth
Jos

Subject: how to manipulate a variable name

From: Jos

Date: 8 Apr, 2008 05:47:01

Message: 4 of 9

Adam Chapman <adam.chapman@student.manchester.ac.uk> wrote
in message
<14732535-a9c0-48ff-bc0a-d5a3230022af@u12g2000prd.googlegroups.com>...
> Hello,
>
> I am trying to order some neural networks into ascending
accuracy. Now
> I want to save the nets in a file so that the most
accurate is called
> 'net1', the second most accurate 'net2' and so on.
>
> Here's some code to describe what im trying to do..
>
> accuracy=rand(1,5)
> SORTED=accuracy; % put accuracy into a matrix that can be
ordered with
> net index
> SORTED(2,1:length(accuracy))=1:length(accuracy); % net
number or index
> SORTED=SORTED';
> SORTED=sortrows(SORTED); %sort nets in terms of accuracy
> SORTED=SORTED';
>
> accuracy=SORTED(1,:); %sorted accuracy
> nets=SORTED(2,:);
>
>
> now, for example we might have
> nets =
>
> 2 3 1 4 5
>
>
> so now i want to save the current net2 as net1,
> the curent net3 as net2,
> the curent net1 as net3, etc
>
> Is this even possible? I've been racking my brains against
this one
> for a couple of hours

Do not setup your variables like this in the first place.
Use cell arrays or rows of matrices. Then shuffling becomes
quite easy!

mynet = {'A','B','C','D','E'} ; % 5 values
nets = [2 3 1 4 5] % new order
mynet = mynet(nets) % shuffled

hth
Jos

Subject: how to manipulate a variable name

From: Adam Chapman

Date: 8 Apr, 2008 11:51:36

Message: 5 of 9

On Apr 8, 6:47=A0am, "Jos " <DEL...@jasenDEL.nl> wrote:
> Adam Chapman <adam.chap...@student.manchester.ac.uk> wrote
> in message
> <14732535-a9c0-48ff-bc0a-d5a323002...@u12g2000prd.googlegroups.com>...
>
>
>
>
>
> > Hello,
>
> > I am trying to order some neural networks into ascending
> accuracy. Now
> > I want to save the nets in a file so that the most
> accurate is called
> > 'net1', the second most accurate 'net2' and so on.
>
> > Here's some code to describe what im trying to do..
>
> > accuracy=3Drand(1,5)
> > SORTED=3Daccuracy; % put accuracy into a matrix that can be
> ordered with
> > net index
> > SORTED(2,1:length(accuracy))=3D1:length(accuracy); % net
> number or index
> > SORTED=3DSORTED';
> > SORTED=3Dsortrows(SORTED); %sort nets in terms of accuracy
> > =A0SORTED=3DSORTED';
>
> > accuracy=3DSORTED(1,:); %sorted accuracy
> > nets=3DSORTED(2,:);
>
> > now, for example we might have
> > nets =3D
>
> > =A0 =A0 =A02 =A0 =A0 3 =A0 =A0 1 =A0 =A0 4 =A0 =A0 5
>
> > so now i want to save the current net2 as net1,
> > the curent net3 as net2,
> > the curent net1 as net3, etc
>
> > Is this even possible? I've been racking my brains against
> this one
> > for a couple of hours
>
> Do not setup your variables like this in the first place.
> Use cell arrays or rows of matrices. Then shuffling becomes
> quite easy!
>
> mynet =3D {'A','B','C','D','E'} ; % 5 values
> nets =3D [2 3 1 4 5] % new order
> mynet =3D mynet(nets) % shuffled
>
> hth
> Jos- Hide quoted text -
>
> - Show quoted text -

The problem with that method is that neural networks made with the
neural net toolbox are of 'network' data type. They cannot be put into
a cell array for some reason. Thanks anyway, I think anyone searching
this problem will be able to find the solution in this thread

Adam

Subject: how to manipulate a variable name

From: Peter Boettcher

Date: 8 Apr, 2008 13:12:12

Message: 6 of 9

Adam Chapman <adam.chapman@student.manchester.ac.uk> writes:

> On Apr 8, 6:47 am, "Jos " <DEL...@jasenDEL.nl> wrote:
>> Adam Chapman <adam.chap...@student.manchester.ac.uk> wrote
>> in message
>> <14732535-a9c0-48ff-bc0a-d5a323002...@u12g2000prd.googlegroups.com>...
>>
>>
>>
>>
>>
>> > Hello,
>>
>> > I am trying to order some neural networks into ascending
>> > accuracy. Now I want to save the nets in a file so that the most
>> > accurate is called 'net1', the second most accurate 'net2' and so
>> > on.
>>
>> > Here's some code to describe what im trying to do..
>>
>> > accuracy=rand(1,5)
>> > SORTED=accuracy; % put accuracy into a matrix that can be
>> ordered with
>> > net index
>> > SORTED(2,1:length(accuracy))=1:length(accuracy); % net
>> number or index
>> > SORTED=SORTED';
>> > SORTED=sortrows(SORTED); %sort nets in terms of accuracy
>> >  SORTED=SORTED';
>>
>> > accuracy=SORTED(1,:); %sorted accuracy
>> > nets=SORTED(2,:);
>>
>> > now, for example we might have
>> > nets =
>>
>> >      2     3     1     4     5
>>
>> > so now i want to save the current net2 as net1,
>> > the curent net3 as net2,
>> > the curent net1 as net3, etc
>>
>> > Is this even possible? I've been racking my brains against
>> this one
>> > for a couple of hours
>>
>> Do not setup your variables like this in the first place.
>> Use cell arrays or rows of matrices. Then shuffling becomes
>> quite easy!
>>
>> mynet = {'A','B','C','D','E'} ; % 5 values
>> nets = [2 3 1 4 5] % new order
>> mynet = mynet(nets) % shuffled
>>
>> hth
>> Jos- Hide quoted text -
>>
>> - Show quoted text -
>
> The problem with that method is that neural networks made with the
> neural net toolbox are of 'network' data type. They cannot be put into
> a cell array for some reason. Thanks anyway, I think anyone searching
> this problem will be able to find the solution in this thread

What?

networks{1} = network(1,2);

I'm glad you found a solution you're happy with. Nonetheless, I want
others who may search this thread to see a solution that it a little
cleaner/more maintainable.

As far as sorting goes, the second output from "sort" will give you the
indices you need, instead of building your own list and using sortrows.
For the example above:

accuracy=rand(1,5);
[sorted_accuracy nets] = sort(accuracy);

That's it. Then use Jos's solution from above.

sorted_nets = networks{nets}


-Peter

Subject: how to manipulate a variable name

From: Yuri Geshelin

Date: 8 Apr, 2008 13:45:35

Message: 7 of 9

The answer to your question is yes, it is possible:

netnum = 2;
eval(['net' num2str(netnum) '=net;'])

However, note that I was fairly criticized for the use of
eval here in a recent discussion.

See
http://www.mathworks.com/matlabcentral/newsreader/view_threa
d/166432

This is a sloppy programming style. Better follow Peter's
and Jos's suggestions.

But it is possible, just so you know.


Adam Chapman <adam.chapman@student.manchester.ac.uk> wrote
in message <14732535-a9c0-48ff-bc0a-
d5a3230022af@u12g2000prd.googlegroups.com>...
> Hello,
>
> I am trying to order some neural networks into ascending
accuracy. Now
> I want to save the nets in a file so that the most
accurate is called
> 'net1', the second most accurate 'net2' and so on.
>
> Here's some code to describe what im trying to do..
>
> accuracy=rand(1,5)
> SORTED=accuracy; % put accuracy into a matrix that can be
ordered with
> net index
> SORTED(2,1:length(accuracy))=1:length(accuracy); % net
number or index
> SORTED=SORTED';
> SORTED=sortrows(SORTED); %sort nets in terms of accuracy
> SORTED=SORTED';
>
> accuracy=SORTED(1,:); %sorted accuracy
> nets=SORTED(2,:);
>
>
> now, for example we might have
> nets =
>
> 2 3 1 4 5
>
>
> so now i want to save the current net2 as net1,
> the curent net3 as net2,
> the curent net1 as net3, etc
>
> Is this even possible? I've been racking my brains
against this one
> for a couple of hours

Subject: how to manipulate a variable name

From: Yuri Geshelin

Date: 8 Apr, 2008 13:47:02

Message: 8 of 9

This link is not working. What solution did you find?

Adam Chapman <adam.chapman@student.manchester.ac.uk> wrote
in message <66e59d44-430c-4166-b4ea-
cf2d5ccba18f@h1g2000prh.googlegroups.com>...
> On Apr 7, 8:35=A0pm, Adam Chapman
> <adam.chap...@student.manchester.ac.uk> wrote:
> > Hello,
> >
> > I am trying to order some neural networks into
ascending accuracy. Now
> > I want to save the nets in a file so that the most
accurate is called
> > 'net1', the second most accurate 'net2' and so on.
> >
> > Here's some code to describe what im trying to do..
> >
> > accuracy=3Drand(1,5)
> > SORTED=3Daccuracy; % put accuracy into a matrix that
can be ordered with
> > net index
> > SORTED(2,1:length(accuracy))=3D1:length(accuracy); %
net number or index
> > SORTED=3DSORTED';
> > SORTED=3Dsortrows(SORTED); %sort nets in terms of
accuracy
> > =A0SORTED=3DSORTED';
> >
> > accuracy=3DSORTED(1,:); %sorted accuracy
> > nets=3DSORTED(2,:);
> >
> > now, for example we might have
> > nets =3D
> >
> > =A0 =A0 =A02 =A0 =A0 3 =A0 =A0 1 =A0 =A0 4 =A0 =A0 5
> >
> > so now i want to save the current net2 as net1,
> > the curent net3 as net2,
> > the curent net1 as net3, etc
> >
> > Is this even possible? I've been racking my brains
against this one
> > for a couple of hours
>
> I found a solution for renaming variables:
>
http://www.mathworks.com/matlabcentral/fileexchange/loadFile
.do?objectId=3D8=
> 677

Subject: how to manipulate a variable name

From: Adam Chapman

Date: 8 Apr, 2008 21:40:57

Message: 9 of 9

On Apr 8, 2:47=A0pm, "Yuri Geshelin" <geshe...@hotmail.com> wrote:
> This link is not working. What solution did you find?
>
> Adam Chapman <adam.chap...@student.manchester.ac.uk> wrote
> in message <66e59d44-430c-4166-b4ea-
> cf2d5ccba...@h1g2000prh.googlegroups.com>...> On Apr 7, 8:35=3DA0pm, Adam =
Chapman
> > <adam.chap...@student.manchester.ac.uk> wrote:
> > > Hello,
>
> > > I am trying to order some neural networks into
>
> ascending accuracy. Now
>
>
>
> > > I want to save the nets in a file so that the most
> accurate is called
> > > 'net1', the second most accurate 'net2' and so on.
>
> > > Here's some code to describe what im trying to do..
>
> > > accuracy=3D3Drand(1,5)
> > > SORTED=3D3Daccuracy; % put accuracy into a matrix that
> can be ordered with
> > > net index
> > > SORTED(2,1:length(accuracy))=3D3D1:length(accuracy); %
> net number or index
> > > SORTED=3D3DSORTED';
> > > SORTED=3D3Dsortrows(SORTED); %sort nets in terms of
> accuracy
> > > =3DA0SORTED=3D3DSORTED';
>
> > > accuracy=3D3DSORTED(1,:); %sorted accuracy
> > > nets=3D3DSORTED(2,:);
>
> > > now, for example we might have
> > > nets =3D3D
>
> > > =3DA0 =3DA0 =3DA02 =3DA0 =3DA0 3 =3DA0 =3DA0 1 =3DA0 =3DA0 4 =3DA0 =3D=
A0 5
>
> > > so now i want to save the current net2 as net1,
> > > the curent net3 as net2,
> > > the curent net1 as net3, etc
>
> > > Is this even possible? I've been racking my brains
> against this one
> > > for a couple of hours
>
> > I found a solution for renaming variables:
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile
> .do?objectId=3D3D8=3D
>
>
>
> > 677- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

ok thanks for all comments and sorry for my mistake, i'm not used to
using cell format yet

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us