Re: variables/objects with sequential naming?
- To: mathgroup at smc.vnet.net
- Subject: [mg130182] Re: variables/objects with sequential naming?
- From: Oliver Jennrich <oliver.jennrich at gmx.net>
- Date: Mon, 18 Mar 2013 05:34:07 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20130316071540.34E2969C3@smc.vnet.net>
Waclaw Kusnierczyk <waku at idi.ntnu.no> writes: > On 03/16/2013 02:15 AM, northerndream at 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 Is there anything wrong with graph=Graph[ cities, DeleteDuplicates[#] ] &/@ edges or should it be required to only pick *some* of the edges and not all graph=Graph[ cities, DeleteDuplicates[#] ] &/@ edges[[;;imax]] graph=Graph[ cities, DeleteDuplicates[#] ] &/@ edges[[imin;;imax]] graph=Graph[ cities, DeleteDuplicates[#] ] &/@ edges[[{somi}]] -- Space - The final frontier
- References:
- variables/objects with sequential naming?
- From: northerndream@gmail.com
- variables/objects with sequential naming?