Java 数组索引的界

Java 数组索引的界,java,arrays,dataframe,loops,processing,Java,Arrays,Dataframe,Loops,Processing,我正在尝试从以下表格创建2d数组,不幸的是,当我尝试迭代表格以将数组值设置为与表格值相同时,我不断收到以下错误: 6497 total rows in table 13 total columns in table ArrayIndexOutOfBoundsException: Column 13 does not exist. 下面是我的代码。顺便说一下,我正在java模式下使用处理 Table table; float[][] variablesDataframe = new float

我正在尝试从以下表格创建2d数组,不幸的是,当我尝试迭代表格以将数组值设置为与表格值相同时,我不断收到以下错误:

6497 total rows in table
13 total columns in table
ArrayIndexOutOfBoundsException: Column 13 does not exist.

下面是我的代码。顺便说一下,我正在java模式下使用处理

Table table;
float[][] variablesDataframe = new float[12][6497];

table = loadTable("/data/winequalityN.csv", "header"); //Importing our dataset
println(table.getRowCount() + " total rows in table"); //Print the number of rows in the table
println(table.getColumnCount() + " total columns in table"); //Print the number of columns in the table

for (int i = 0; i < table.getColumnCount(); i++){
  for (int j = 0; j < table.getRowCount(); j++){
    variablesDataframe[i][j] = table.getFloat(i + 1, j);    
  }
}
表格;
float[]variablesDataframe=新的float[12][6497];
table=loadTable(“/data/winequalityN.csv”,“header”)//导入我们的数据集
println(table.getRowCount()+“表中的行总数”)//打印表中的行数
println(table.getColumnCount()+“表中的总列”)//打印表中的列数
对于(int i=0;i
我跳过第一列(I+1)的原因是因为它是dtype String/Object,我只想要float,它是我的2d数组中数据集的其余部分

如果有人能帮我实现这一点或修复代码将不胜感激


干杯。

您的可变数据帧数组定义为[12][6497]

在您的代码中,您的第一个for循环从0初始化i,它将继续迭代,直到达到13。所以,总共得到13个i值

for (int i = 0; i < table.getColumnCount(); i++){
  for (int j = 0; j < table.getRowCount(); j++){
    variablesDataframe[i][j] = table.getFloat(i + 1, j);    
  }
}
for(int i=0;i
由于要跳过第一行,请改为这样做

 for (int i = 0; i < table.getColumnCount()-1; i++){ 
      for (int j = 0; j < table.getRowCount()-1; j++){
        variablesDataframe[i][j] = table.getFloat(i+1, j); 
      }
 }
for(inti=0;i

这将确保跳过第一行,并且数组中只有12个值。行也是如此。

您能给我们看一下您的Table类吗?当然可以?您将
variablesDataframe
声明为
float[12][6497]
,因此,当您尝试将不存在的内容放入
variablesDataframep[12]
(只有索引0到11存在)时,您会得到一个错误。在开始循环之前,确保表和数据框的大小相互匹配。表有13列<使用
i+1
调用code>getFloat
,因此值的范围从1到13,并且
表中没有索引13
。同样对于
variablesDataframe[i][j]
而言,索引
i
从0变为12,但该数组中没有索引12。他希望忽略第一个表的列。你的
i
for循环需要像
i
,这样当你调用
table.getFloat(i+1,j)
时,它不会溢出是的,我理解你的意思。但是,当我使用您编写的代码时,仍然会出现相同的错误。我使用的是处理,可能与此有关?什么样的处理?处理3.5.4,但nvm我和我的老师一起解决了。无论如何,谢谢你的帮助,非常感谢。