Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7876351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:09:15+00:00 2026-06-03T03:09:15+00:00

Im interested in doing some matrix calculations in objective-C (for an iPhone app). A

  • 0

Im interested in doing some matrix calculations in objective-C (for an iPhone app).

A score should be calculated for every element in the matrix, but I can’t even get my initialization of the matrix to work.
The algorithm i’m trying to implement is called the Needleman-Wunsch algorithm, is used to align nucleotide sequences.

Currently, I am trying to initialize a 2d array, be defining an array, and then fill every element of the array with another array, but it does not seem to work.
My current go looks like this:

-(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]);
}

Any ideas how to acomplish this? (I’m a newbie to objective-C, so sorry if there are stupid questions or obvious errors in the code)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:09:16+00:00Added an answer on June 3, 2026 at 3:09 am

    Yowza! It’s been a while… here goes nothing:

    NSMutableArray *horizontalArray = [[NSMutableArray alloc] initWithCapacity:intSections];
    
    for (int i=0; i <= intSections; i++) {
    
        NSMutableArray *innerArray = [[NSMutableArray alloc] initWithCapacity:intRows];
    
        for (int j=0; j <= intRows; j++) {
            [innerArray addObject:[NSNumber numberWithInt:0]];
        }
    
        [horizontalArray addObject:innerArray];
        [innerArray release];
    }    
    

    Assuming it works, this is a little cleaner and it should do what you’re attempting without inviting indexing errors. On that note, it looks like you’re initializing your inner array with more space than necessary. This won’t cause an indexing error, but observe:

    [horizontalArray insertObject:[[NSMutableArray alloc] initWithCapacity:intSections] atIndex:i];
    

    I think it would be better like this:

    [horizontalArray insertObject:[[NSMutableArray alloc] initWithCapacity:intRows] atIndex:i];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in doing some Collective Intelligence programming, but wonder how it can
I'm interested in doing some development against the Safari browser but I'm not sure
I am interested in doing some snail mail based surveys but I am looking
I am trying to get started doing some Silverlight development. I am interested in
I'm interested in doing something like an enum but where the increments aren't always
Not that I'm doing something like that, but I am kind of interested how
I've been doing some reading on file formats and I'm very interested in them.
I am interested in doing some development with XNA. One of the things that
I was interested in doing some cross platform work with a usb device in
I have C code doing some calculations (irrelevant to my question, I believe ).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.