下面的代碼我想發送matrix1Col和matrix2Col乘法。索引1超出範圍時出錯
但它與索引1超出邊界的錯誤。
從
double kk[2][2] = {{1,2},{5,6}};
double t [2][1] = {1,2};`
if (!matrix1Col) {
matrix1Col = [NSMutableArray array];
}
for (unsigned int i=0; i<2; i++) {
matrix1Row = [NSMutableArray new];
for (unsigned int j=0 ; j<2; j++) {
[matrix1Row addObject:@(kk[i][j])];
}
[matrix1Col addObject:matrix1Row];
}
if (!matrix2Col) {
matrix2Col = [NSMutableArray array];
}
for (unsigned int i=0; i<2; i++) {
matrix2Row = [NSMutableArray new];
for (unsigned int j=0; j<1; j++) {
[matrix2Row addObject:@(t[i][j])];
}
[matrix2Col addObject:matrix2Row];
}
NSMutableArray *resultMultiply = [self multiply:matrix1Col :matrix2Col];
在ViewController.m另一種方法裏面的UIButton代碼:
這是錯誤代碼:
2013-02-14 06:26:06.595 matrixMutableArray[21578:c07] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
我找不到它在那裏的錯誤。
感謝您的評論。
錯誤發生在哪裏? – Sebastian 2013-02-14 00:04:15