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

3 ビュー (過去 30 日間)
Molly
Molly 2025 年 4 月 25 日
コメント済み: Molly 2025 年 4 月 25 日
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 件のコメント
Torsten
Torsten 2025 年 4 月 25 日
編集済み: Torsten 2025 年 4 月 25 日
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 2025 年 4 月 25 日
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!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGravitation, Cosmology & Astrophysics についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by