Message Boards Message Boards

0
|
5924 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Creating Table Elements as Strings Without Quotes

Posted 10 years ago

I am creating a number of tables with some table elements being strings and some table elements being numbers. For the elements that are strings I would like to use either Module or Package to limit the scope of the string names to this table in an input cell without duplicating the entire table list in the Module list. Is there an easy way to do this? Basically I want to be able to create a "scope wrapper" around a table and add entries as I would in a spreadsheet without the need for quotes around the strings. I also tried using the (undocumented) TableView which allows me to enter items in each cell without quotes - see example image below - but that intermittently crashes my notebook.

Here is an example for a table with all of the elements represented as strings:

myData = {{"Silicon Image", "address-1", "address-2", "address-3"},
         {"a version", "value-1", "value-2", "value-3"},
         {"another version", "value-4", "value-5", "value-6"}
} ;
Grid[myData, Alignment -> Center, Spacings -> {2, 1}, Frame -> All, 
 ItemStyle -> "Text", Background -> {{LightBlue, None}, {LightYellow, None}}]

How would I place this table in a Module allowing each element in the table (with quotes removed from the strings), to be a local symbol within the scope of this Module? This Doesn't work and I would rather not repeat each of the table element strings in the module variable list

    Module[{{SiliconImage, address-1, address-2, address-3},
             {a version, value-1, value-2, value-3}
             {another version, value-4, value-5, value-6}},
    myData = {{SiliconImage, address-1, address-2, address-3},
             {a version, value-1, value-2, value-3}
             {another version, value-4, value-5, value-6}
    } ;
    Grid[myData, Alignment -> Center, Spacings -> {2, 1}, Frame -> All, 
     ItemStyle -> "Text", Background -> {{LightBlue, None}, {LightYellow, None}}]
    ]

Module::lvsym: Local variable specification {{SiliconImage,address-1,address-2,address-3},{a version,value-1,value-2,value-3} {another version,value-4,value-5,value-6}} contains {SiliconImage,address-1,address-2,address-3}, which is not a symbol or an assignment to a symbol. >>

enter image description here

POSTED BY: Bob Stephens
2 Replies
Posted 10 years ago

Thanks Udo - your solution works and eliminates the need to duplicate the list of strings in the module list.

POSTED BY: Bob Stephens

This will do it

In[1]:= myData = {{"Silicon Image", "address-1", "address-2", 
    "address-3"}, {"a version", "value-1", "value-2", 
    "value-3"}, {"another version", "value-4", "value-5", "value-6"}};

In[6]:= Clear[stephensTab]
stephensTab[m_?MatrixQ] := Module[{mLoc = m},
  Grid[mLoc, Alignment -> Center, Spacings -> {2, 1}, Frame -> All, 
   ItemStyle -> "Text", 
   Background -> {{LightBlue, None}, {LightYellow, None}}]
  ]

In[8]:= stephensTab[myData]
POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract