51,411
社区成员
发帖
与我相关
我的任务
分享 protected void buttonPerformed3_1(ActionEvent e) {
String str3 = textField_1.getText();//输入第一行文本,例如1,2,3,4,5,6,7,8,9
String str4 = textField_2.getText();//输入第二行文本,规则同上
String[] strArr3 = str3.split(",");
String[] strArr4 = str4.split(",");
//将接收到的文本转化为double数组
int index = 0;
double array3[][] = new double[3][3];
double array4[][] = new double[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
array3[i][j] = Double.parseDouble(strArr3[index]); //array3[][] ={[1,2,3][4,5,6][7,8,9]}
array4[i][j] = Double.parseDouble(strArr4[index]);
index++;
}
}
// 创建矩阵对象
MWNumericArray A = new MWNumericArray((array3), MWClassID.SINGLE);
MWNumericArray B = new MWNumericArray((array4), MWClassID.SINGLE);
MWNumericArray C =null;
Object[] obj = null;
Mymatrix matrix = null;//m文件,返回两个矩阵的和
try {
matrix = new Mymatrix();
obj = matrix.myadd(0, A, B);//为什么前面不加0会报错,我的函数只需要两个参数 function c = myadd(a,b)
} catch (MWException e1) {
e1.printStackTrace();
return;
}
//不需要输出语句,控制台已经自动出现矩阵结果,不明白原因,是不是我的m文件写得有问题
//用输出语句却打印不出矩阵了
System.out.println(obj); //打印结果:[Ljava.lang.Object;@58faf771
System.out.println(obj[0]);//这句话会报错,obj[]数组0角标为什么也会越界Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
}function c = myadd(a,b)
c = a+b