Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Copying portions of a large array into a smaller one
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Joeltron




PostPosted: Fri Apr 05, 2013 9:21 pm   Post subject: Copying portions of a large array into a smaller one

I need help making a copy of portions of a larger array in a smaller array. what i am trying to do is load an image raster (which is an array), and then crop the image, by making a copy of the data in select bins. The image below helps to explain what im trying to do. the larger array has been written out in the form it makes the raster image. the bin numbers have been written out. what i need to do is make a copy of just the highlighted bins in the smaller array. so copy[0,1,2,3] will be equal to bigArray[14,15,20,21]


image.jpeg
 Description:
 Filesize:  149.19 KB
 Viewed:  250 Time(s)

image.jpeg


Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri Apr 05, 2013 9:31 pm   Post subject: RE:Copying portions of a large array into a smaller one

You can easily do this with a nested for loop.

code:
int x_offset, y_offset
int x_size, y_size

array old_array, new_array

for (int x = 0; x < x_size, x++){
    for (int y = 0; y < y_size, y++){
        new_array[x][y] = old_array[x+x_offset][y+y_offset]
    }
}
Joeltron




PostPosted: Fri Apr 05, 2013 9:55 pm   Post subject: Re: Copying portions of a large array into a smaller one

im using a standard java array. which looks like array[bin], so im not too sure what you mean by new_array[x][y]. any further explanation would be awesome. thanks.
Tony




PostPosted: Fri Apr 05, 2013 10:18 pm   Post subject: RE:Copying portions of a large array into a smaller one

you can think of it as array of arrays. So the value of 2D_array[0] would be an array with values such as [0,6,12,18,24,30]
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: