Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
waku

Posts: 14
Registered: 1/27/11
Re: variables/objects with sequential naming?
Posted: Mar 17, 2013 3:09 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 03/16/2013 02: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]]];
> ...


One direct solution would be

Do[
Set@@{ToExpression["graph"<>ToString@i], Graph[cities,
DeleteDuplicates@edges[[i]]]},
{i, imax}]

where imax is the upper bound on your index variable.

Alternatively,

Do[
graph[i] = Graph[cities, DeleteDuplicates@edges[[i]]],
{i, imax}]

so that graph1 becomes graph[1], etc. Or, maybe even better,

graph = Table[Graph[cities, DeleteDuplicates@edges[[i]]], {i, imax}]

so that graph1 becomes graph[[1]], etc.

vQ

>
> 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
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.