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 9280293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:50:08+00:00 2026-06-18T17:50:08+00:00

As following code I wanna send matrix1Col and matrix2Col to multiply method. But it’s

  • 0

As following code I wanna send matrix1Col and matrix2Col to multiply method.

But it’s error with index 1 beyond bounds.

From inside UIButton code

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];

Another method in ViewController.m:

-(NSMutableArray*)multiply:(NSMutableArray*)matrix1 :(NSMutableArray*)matrix2{
int matrix1RowCount = [matrix1 count];
int matrix2RowCount = [matrix2 count];
int matrix2ColCount = [[matrix2 objectAtIndex:0] count];

NSMutableArray *multiplyMatrix = [NSMutableArray arrayWithCapacity:matrix1RowCount];
for (int i=0; i< matrix1RowCount; i++) {
    NSMutableArray *matrixInRow = [NSMutableArray arrayWithCapacity:matrix2ColCount];
    for (int j=0; j<matrix2RowCount; j++) {
        double valueTotal = 0;
        for (int k=0; k<matrix2ColCount; k++) {
            double value1 = [[[matrix1 objectAtIndex:i] objectAtIndex:k] doubleValue];
            double value2 = [[[matrix2 objectAtIndex:k] objectAtIndex:j] doubleValue];
            valueTotal += value1*value2;
        }
        [matrixInRow addObject:[NSNumber numberWithDouble:valueTotal]];
    }
    [multiplyMatrix addObject:matrixInRow];
}
return multiplyMatrix;
}

This is error code:

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:

I can’t find it where it’s error.

Thanks you for your comment.

  • 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-18T17:50:09+00:00Added an answer on June 18, 2026 at 5:50 pm

    The error occurs on this row:

    double value2 = [[[matrix2 objectAtIndex:k] objectAtIndex:j] doubleValue];
    

    When the error occurs k=0 and j=1. The objectAtIndex:0 for matrix2 only has one object, hence the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanna update remote table with following code but I encounter this error: `Msg
Following code is generated by a for loop. <form action=saveresponse.php method=POST name=mainForm> <input class=cbox_yes
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
I wanna check radio buttons automatically: I tried this code but it does not
The following code works perfectly. My only concern is that I wanna convert below
I already have the following code: atom_length(Var, Len) :- length(Var, Len). I wanna construct
I wanna login to my university webmail page by curllib. I program following code
I know I can open Windows Calculator with the following code : System.Diagnostics.Process.Start(calc); But
I'm using the following code: $(#galleries).load(letters/index.php); $(function(){ $('#galleries').hide().fadeIn(1500); }); everything works fine. My problem
Following code produces a nested array as a result for keys containing three items:

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.