Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13854 > unrolled thread
| Started by | northerndream@gmail.com |
|---|---|
| First post | 2013-03-16 07:14 +0000 |
| Last post | 2013-03-18 09:34 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
variables/objects with sequential naming? northerndream@gmail.com - 2013-03-16 07:14 +0000
Re: variables/objects with sequential naming? Stefano Ugliano <northerndream@gmail.com> - 2013-03-18 09:34 +0000
| From | northerndream@gmail.com |
|---|---|
| Date | 2013-03-16 07:14 +0000 |
| Subject | variables/objects with sequential naming? |
| Message-ID | <ki1641$5v0$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | Stefano Ugliano <northerndream@gmail.com> |
|---|---|
| Date | 2013-03-18 09:34 +0000 |
| Message-ID | <ki6n2v$ge1$1@smc.vnet.net> |
| In reply to | #13854 |
Il giorno sabato 16 marzo 2013 08:14:09 UTC+1, Stefano Ugliano ha scritto:
> 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
Dear All,
I have recevied some answer to my question that I am posting here. Thank you all, as from each of them I found out some interesting command I did not
know much about.
First of all, the "winning" answer in term of doing exactly what i wanted in the most elegant and simple way one could think of was:
graph = Graph[cities, DeleteDuplicates[#]]& /@ edges
This gives no "graph1, graph2" etc. but working from the graph list one takes graph[[1]] and so on and it's the same, if not better since Mathematica is so good at handling lists
----------
This other answer was interesting as it allows to obtain items with actually the required name:
set [ name_String, val_ ] := ( Clear[name]; Set [ Evaluate [ Symbol [
name ]] , val ] );
setGraph [ k_Integer ] :=
set [ "graph" <> ToString [k], Graph [ cities,
DeleteDuplicates@edges [ [ 1 ] ] ] ];
although I guess the last [[1]] should be [[k]]: problem is, this doesn't work in building the graphs... but the general scheme is quite precious for other cases, I just hope that calling back a variable in the format "name_number" is just as easy, I'm starting to think that lists are *the* solution to this kind of problems..
This one proposed by Waclaw instead works on all the line:
Do[
Set@@{ToExpression["graph"<>ToString@i], Graph[cities,DeleteDuplicates@edges[[i]]]},{i, imax}]
While I still have to try this one
Do[
graph[i] = Graph[cities, DeleteDuplicates@edges[[i]]],{i, imax}]
In any case thanks to all of you who sent me an answer, they were all very appreciated and helpful.
- Stefano
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web