0
$\begingroup$

I was told as:

AdjacencyGraph::matsq: Argument {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<461>>},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,<<461>>},<<48>>,<<461>>}} at position 2 is not a non-empty square matrix.

However, the matrix is imported from Microsoft Excel which is exactly a [511 x 511] square matrix.

$\endgroup$
2
  • 1
    $\begingroup$ You probably have additional {} after importing from excell since it returns a list of sheets contents really. So use First and put the result to the AdjacencyGraph. $\endgroup$
    – Kuba
    Commented Jan 25, 2016 at 11:47
  • 6
    $\begingroup$ If that's the case, here's a duplicate: Why an extra { when importing .xls? $\endgroup$
    – Kuba
    Commented Jan 25, 2016 at 11:48

1 Answer 1

1
$\begingroup$

Let's assume you've imported Microsoft Excel spreadsheet into Mathematica:

(*test data*)
data = Import @ "C:\\Users\\-e\\Documents\\data.xlsx";

The output of this would be (given there are 3 columns and 3 rows):

(*output*)
{{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}}

So in order to get your graph you can do something like this:

(*operation, where 'data' is your own imported Microsoft Excel data*)
Flatten[data, 1]

The output of the above operation would be as follows:

(*output*)
{{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}

Then if you apply AdjacencyGraph you get:

AdjacencyGraph @ Flatten[data, 1]

output example

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.