Unclear cause of "Target must be a numeric array of positive integer node indices" error with .csv file

3 visualizaciones (últimos 30 días)
I am attempting to load two large .csv files (~9 million data entries each) into column vectors and then graphing them using g = graph(s,t). I have done significant data scouring to try to find an entry in the data that is not a positive integer, but there are none. Still, I am getting the following errors when I try to graph:
Error using matlab.internal.graph.MLGraph
Target must be a numeric array of positive integer node indices.
Error in matlab.internal.graph.constructFromEdgeList (line 237)
G = matlab.internal.graph.MLGraph(s, t, totalNodes);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in graph (line 329)
matlab.internal.graph.constructFromEdgeList(...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in Project2Debugging (line 4)
g = graph(s,t);
I've tried using readtable, readmatrix, and csvread. readtable takes too long to run, and I get the same error using both csvread and readmatrix to onboard the data.
Here is the code using readmatrix:
s = transpose(readmatrix("s_file.csv"));
t = transpose(readmatrix("t_file.csv"));
g = graph(s,t);
Here is the code using csvread:
s = csvread("s_file.csv");
t = csvread("t_file.csv");
g = graph(s,t);
Here is the code I used to check for improper data entries. I tested it on small sample vectors to ensure it would detect negative numbers, zeros, decimals, and NaN's
for i=1:1:8935316
if s(i,1)<1 | isinf(s(i,1)) | floor(s(i,1)) ~= s(i,1)
disp("bad s" + i)
end
if t(i,1)<1 | isinf(t(i,1)) | floor(t(i,1)) ~= t(i,1)
disp("bad t" + i)
end
end
  4 comentarios
Torsten
Torsten el 25 de Abr. de 2025
Editada: Torsten el 25 de Abr. de 2025
The maximum node number in both is 1.0026e+21
Node numbers must be integers:
Target must be a numeric array of positive integer node indices.
That's why I recommended the above check, and it's not the case for your s and t.
But if the number of elements of s and t is 8935316, you should be able to renumber the nodes such that the integer constraint holds.
Molly
Molly el 25 de Abr. de 2025
Renumbering the elements worked! I didn't realize that the automatic scientific notation would cause an issue since there aren't any "decimals" otherwise. Thanks for your help!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Gravitation, Cosmology & Astrophysics en Help Center y File Exchange.

Productos


Versión

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by