我有兴趣在 Objective-C 中进行一些矩阵计算(对于 iPhone 应用程序)。
应该为矩阵中的每个元素计算一个分数,但我什至无法让我的矩阵初始化工作。我试图实现的算法称为 Needleman-Wunsch 算法,用于对齐核苷酸序列。
目前,我正在尝试初始化一个二维数组,定义一个数组,然后用另一个数组填充数组的每个元素,但它似乎不起作用。我现在的样子是这样的:
-(IBAction)alignSequences:(id)sender {
NSString *dnaString1 = @"GAATTCAGTTA";
NSString *dnaString2 = @"GGATCGA";
int intSections = (dnaString1.length+1);
int intRows = (dnaString2.length+1);
//The matrix is initialized, and the value of every element is set to 0
NSMutableArray *horizontalArray = [[NSMutableArray alloc] initWithCapacity:intSections];
for (int i=0; i <= intSections; i++) {
[horizontalArray insertObject:[[NSMutableArray alloc] initWithCapacity:intSections] atIndex:i];
for (int j=0; j <= intRows; j++) {
[[[horizontalArray objectAtIndex:i] objectAtIndex:j] insertObject:[NSNumber numberWithInt:0] atIndex:j];
}
}
NSLog(@"%@",[[horizontalArray objectAtIndex:1] objectAtIndex:1]);
}
任何想法如何实现这一点?(我是 Objective-C 的新手,如果代码中有愚蠢的问题或明显的错误,请见谅)