Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: variables/objects with sequential naming?
Replies: 4   Last Post: Mar 18, 2013 5:34 AM

 Messages: [ Previous | Next ]
 James Stein Posts: 130 Registered: 5/8/10
Re: variables/objects with sequential naming?
Posted: Mar 17, 2013 7:48 PM

I recommend writing a general purpose function 'set',
then writing a more specific routine 'setGraph':

set [ name_String, val_ ] := ( Clear[name]; Set [ Evaluate [ Symbol [
name ]] , val ] );
setGraph [ k_Integer ] :=
set [ "graph" <> ToString [k], Graph [ cities,
DeleteDuplicates@edges [ [ 1 ] ] ] ];

On Sat, Mar 16, 2013 at 12:15 AM, <northerndream@gmail.com> wrote:
> Dear all,
>
> the simplest way to explain what I'd like to achieve is to show you the long way I had to go, not knowing how to automate this:
>
> graph1 = Graph[cities, DeleteDuplicates@edges[[1]]];
> graph2 = Graph[cities, DeleteDuplicates@edges[[2]]];
> graph3 = Graph[cities, DeleteDuplicates@edges[[3]]];
> graph4 = Graph[cities, DeleteDuplicates@edges[[4]]];
> graph5 = Graph[cities, DeleteDuplicates@edges[[5]]];
> graph6 = Graph[cities, DeleteDuplicates@edges[[6]]];
> graph7 = Graph[cities, DeleteDuplicates@edges[[7]]];
> ...
>
> and I think you got the point (no need to paste the whole list!)
>
> I will of course have the same problem on the way around, when I'll want to obtain a table of values for all my graph1, graph2...
>
> I used ToString to produce output files with sequential names, but this... no clue! (googling didn't help either)
>
> Could anywone help?
> Thank you
> - Stefano
>

Date Subject Author
3/17/13 waku
3/17/13 Louis Talman
3/17/13 James Stein
3/18/13 Oliver Jennrich