2
$\begingroup$

I have a table to describe a crossroad. Each traffic line has it own Q(flow), V( speed) and direction.

I'm saving data in array, which hardcoded (very simple code data = {{66, 55, 3}, {44, 33, 2}, {22, 11, 1}};) . The functional allows to create more traffic lanes. Now it works, when I change value in inputfield it changes in data_array correctly.

I would like to create an array, without hardcode(it could be full of 0 e.g.), like C++ malloc. It is possible? Thank you!

P.S. After user complete the table, I need to have this array( already changed) and it length(also changed due to user's amount of traffic lines). Then I would give this array to C++ to calculate( but now the question is about malloc array)

resultingControl = Labeled[
Manipulate[
data = {{66, 55, 3}, {44, 33, 2}, {22, 11, 1}};

   e = 0;

   Grid[{

  {Style["direction East", 16, Bold]}
  }~Join~
 Table[
  {Style["traffic lane", Bold], e, 
   Labeled[InputField[Dynamic[data[[#, 1]]] &@e, FieldSize -> 8], 
    "Q", Left, LabelStyle -> Directive[Bold]], 
   Labeled[InputField[Dynamic[data[[#, 2]]] &@e, FieldSize -> 8], 
    "V", Left, LabelStyle -> Directive[Bold]], 
   PopupMenu[
    Dynamic[data[[#, 3]]] &@e, {0 -> "out", 1 -> "left", 
     2 -> "right", 3 -> "straight", 4 -> "straight-left-right", 
     5 -> "straight-left", 6 -> "straight-right", 
     7 -> "left-right"}]}, {e, EastLines}
  ]
],(*direction East*)
  Grid[{
 {DynamicModule[
   {
    code = Hold[EastLines :> 2
      ]
    },
   With[
    {
     fn = (
        code = #;
        ReleaseHold[# /. RuleDelayed -> SetDelayed]
        ) &
     },
    Manipulate[
     Column[
      {

       Labeled[
        InputField[Dynamic[code, fn], Hold[Expression], 
         FieldSize -> 35 ], "", Left, 
        LabelStyle -> Directive[Bold]]
       }
      ],
     Initialization :> fn[code]
     ]
    ]
   ]
  }
 }],(*DynamicModule EastIN*)
   SynchronousInitialization -> False,
   ContinuousAction -> False
   ](* Manipulate *),
  "Lab№2", Top, 
  LabelStyle -> 
   Directive[Bold, Blue, Italic, 24, FontFamily -> "Helvetica"]
  ];  (* Labeled *)
resultingControl
$\endgroup$
  • $\begingroup$ Is that code yours? The complexity of the code doesn't match the complexity of the question, or I'm wrongly understanding the question $\endgroup$ – Dr. belisarius Sep 30 '15 at 14:50
  • $\begingroup$ Partly. I wrote something by myself, something found in internete, something already asked on this forum. Does it matter? I'm sure, You understand correctly.) $\endgroup$ – Mishin V. Sep 30 '15 at 14:56
  • 3
    $\begingroup$ Yes, it does. Because if you can write that code, then you can understand this one, which does exactly what you want $\endgroup$ – Dr. belisarius Sep 30 '15 at 15:08
  • $\begingroup$ Well,thank You! I'll try to figure this out. $\endgroup$ – Mishin V. Sep 30 '15 at 15:11
  • 2
    $\begingroup$ The problem with writing questions containing code you aren't up to (yet) is that the answerers don't know what will be a good path for you. Mathematica can be used at many levels, from basic C code to elaborated meta programing functional. I suggest you start reading this and this $\endgroup$ – Dr. belisarius Sep 30 '15 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.