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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:02:19+00:00 2026-05-22T20:02:19+00:00

I have an array to store a set of coordinates for painting a piece

  • 0

I have an array to store a set of coordinates for painting a piece of line. So here are some example coordinates

double[][] plotMatrix = {{10,20},{55,80},
                         {120,40},{225,30},
                         {327.5,100},
                         {427.5,30},
                         {529,60}};

The next step is to create a markov matrix which is two-dimensional.

enter image description here

First I count the times where a point from the left column is followed by a point in the top column. Since I want a line each point is followed by another single point. That means if we have {10,20} as input the propability of {55,80} being the next point is 100%.

I am not really sure about all this so please correct me!

So this is my matrix

double[][] markovMatrix = { {0.0,1.0,0.0,0.0,0.0,0.0,0.0},
                                    {0.0,0.0,1.0,0.0,0.0,0.0,0.0},
                                    {0.0,0.0,0.0,1.0,0.0,0.0,0.0},
                                    {0.0,0.0,0.0,0.0,1.0,0.0,0.0},
                                    {0.0,0.0,0.0,0.0,0.0,1.0,0.0},
                                    {0.0,0.0,0.0,0.0,0.0,0.0,1.0},
                                    {0.0,0.0,0.0,0.0,0.0,0.0,0.0}};

My algorithm:

    int seed = 0;
    int output = 0;

    for(int i = 0; i < 40;i++){
        double choice = r.nextDouble();

        double currentSum = 0.0;

        for(;output < markovMatrix.length;output++){

            currentSum += markovMatrix[seed][output];

            if(choice <= currentSum){
                break;
            }
        }

        System.out.println(output);
        polygon.lineTo(plotMatrix[output][0], plotMatrix[output][1]);

        seed = output;

        output = 0;
    }

My problem is that I get an ArrayOutOfBoundsException:7 when I try to access both plotMatrix and markovMatrix. However output is set to 0 at the end of each loop. Any ideas how to solve that problem?

  • 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-05-22T20:02:20+00:00Added an answer on May 22, 2026 at 8:02 pm

    I’m not quite sure if its the right answer,

    but for(;output < markovMatrix.length;output++) will step from 0 to 7, while you only have 0 to 6 entries in markovMatrix.

    Using for(;output < markovMatrix.length-1;output++) fixes the ArrayIndexOutOfBoundsException by stepping from 1 to 6.

    However I suspect you really want to step from 0 to 6. And there lies your problem.

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

Sidebar

Related Questions

I have a generated nested Array which I store some data. How can i
I have this routing defined in my module's init.php; Route::set('store', 'store/<store_id>(/<controller>(/<action>(/<id>)))', array( 'store_id' =>
I have an array of ListViewItems ( ListViewItem[] ), where I store a SalesOrderMaster
I have a char array buffer that I am using to store characters that
i have have got an array of the complexe sort to store my navigation
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
How can I store arrays in single array? e.g. I have four different arrays,
I want to store my CGPoint to the NSMutable Array, so , I have
I have array data as shown below, I want to store 'sale' value into
I have roughly 420,000 elements that I need to store easily in a Set

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.