# Import array indices from Excel

In an Excel file, I have some numbers which I will use as the indices of arrays. I want to read those numbers and assign them as the array indices in Mathematica.

For instance, in Excel I have

and I want the rows to be imported as follows in Mathematica:

{{x[[1]], x[[1]], x[[10]], x[[12]], x[[1]], x[[2]], x[[11]], x[[3]]},
{x[[1]], x[[1]], x[[12]], x[[14]], x[[1]], x[[3]], x[[13]], x[[4]]},
... }


• Could you please explain more? I am a beginner user. – Enthusiastic Engineer Jun 17 '14 at 8:28
• The array numbers to be imported are as the picture above. My data is that. – Enthusiastic Engineer Jun 17 '14 at 8:31
• No, that is the excel file in which the numbers are stored, I want mathematica to use those numbers as array counters. But I don't know how. – Enthusiastic Engineer Jun 17 '14 at 8:33
• I added the data to the question. – Enthusiastic Engineer Jun 17 '14 at 8:38
• Question updated – Enthusiastic Engineer Jun 17 '14 at 8:50

Here's another version:

Import["~/Downloads/NodeNumbers.xlsx"] /. ind_Real :> x[[Floor@ind]]

• It worked for me. I used the following syntaxes in the next comments: – Enthusiastic Engineer Jun 17 '14 at 10:29
• x = Flatten[Import[FileNameJoin[{NotebookDirectory[], "x.xlsx"}]]]; – Enthusiastic Engineer Jun 17 '14 at 10:29
• Flatten[Import[ FileNameJoin[{NotebookDirectory[], "NodeNumbers.xlsx"}]] /. ind_Real :> x[[Floor@ind]], 1] – Enthusiastic Engineer Jun 17 '14 at 10:33

arrayList =

will give you the symbol arrayList containing the list of lists of x indexed using the values in the spreadsheet.
Note that if x does not already exist with enough values, you'll get error messages. You can append //Quiet to the above if you just want a list of lists of indexed x - if/when you create and fill x, arrayList entries will take on the appropriate values. The messages (if x does not exist in proper form) are from attempting to reference something non-existent. You could also Hold the entries to avoid this, but I'm not clear what the end result you're after is...
• note you can do the Map on level 1 just as well : x[[#]] & /@ First@Round[Import["file.xlsx"]] -- might be a tad faster, then again the excel import performance likely dwarfs that difference. – george2079 Jun 17 '14 at 17:16