View unanswered posts | View active topics It is currently Fri Jul 01, 2016 7:49 am

 Page 1 of 1 [ 13 posts ]
 Print view Previous topic | Next topic
4-dimensional arrays ?
Author Message
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
4-dimensional arrays ?
hi,
I need 4 dimensional arrays of int in my program.
Strangely RobotC supports only 2 dimensions, but this is far too little.
Could you please enable more dimensional arrays in a future (maybe in the next) release?

Sat Oct 11, 2008 4:50 pm
Rookie

Joined: Sun Sep 28, 2008 1:06 pm
Posts: 27
Re: 4-dimensional arrays ?
wow 4D arrays? not many languages support this at all i believe...could you please tell us what your application is and maybe we can help you find a workaround?

Sat Oct 11, 2008 11:29 pm
Rookie

Joined: Wed Apr 30, 2008 7:05 am
Posts: 18
Location: Brisbane, QLD
Re: 4-dimensional arrays ?
i dodged up 3d arrays by using structs. Im sure u can do the same with 4d.
This works for 3d
 Code:typedef struct {   int array2D[sizeX][sizeY]; //using an array of structures to create [][][]} 3Dmatrix;3Dmatrix test[sizeZ];

You could always try:-

 Code:typedef struct {   int array2D[sizeX][sizeY]; //using an array of structures to create [][][][]} 3Dmatrix;3Dmatrix test[sizeZ][sizeK];

_________________
experiencing slow death by thesis

Sun Oct 12, 2008 12:33 am
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Re: 4-dimensional arrays ?
 basicxman wrote:wow 4D arrays? not many languages support this at all i believe...

In ANSI C, 7-dimensional arrays are standard!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Sun Oct 12, 2008 4:57 am
Rookie

Joined: Sun Sep 28, 2008 1:06 pm
Posts: 27
Re: 4-dimensional arrays ?
Ford Prefect wrote:
 basicxman wrote:wow 4D arrays? not many languages support this at all i believe...

In ANSI C, 7-dimensional arrays are standard!

guess i learned something new today. 7D eh? wow... still curious as to your application spaceballs

Sun Oct 12, 2008 11:54 am
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Re: 4-dimensional arrays ?
it's for kind of look up table

Sun Oct 12, 2008 12:50 pm
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Re: 4-dimensional arrays ?
@ the developers:
Could you please enlarge the maximum of dimensions?
It's very urgent, and it should not be a problem to just raise the dim limit up to the standards!

Sat Oct 18, 2008 6:40 am
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Re: 4-dimensional arrays ?
I'm one of the developers.

This is not an easy limit to "simply change a constant to increase the limit".

I will add this to the list of possible feature requests.

Meanwhile you can work around it as someone has suggested with a two dimensional struct containing a two dimensional member variable.

Mon Oct 20, 2008 3:21 pm
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Re: 4-dimensional arrays ?
hi,
thx, I'll try it, but I think it won't be easy.

Tue Oct 21, 2008 5:36 am
Expert

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Re: 4-dimensional arrays ?
There is a simpler solution to create a multidimensional array. The trick is to convert it to a one dimensional array. I'll explain using a two dimensional array as an example, but the trick works for any number of dimensions.

Suppose you want a 2 dimensional array with 10 positions in each dimension. This array has 10 times 10 equals 100 positions. So a one dimensional array of 100 positions can store exactly the same amount of information. In general, the required length of a one dimensional array equals the product of the dimensions of a multidimensional array.

This leaves only the problem of addressing each item in your array. But, this can also be solved using a little math. Suppose you want to address row=1 and col=3 in a two-dimensional array. For a one-dimensional array this address can be translated to 13 (=10*row+col). The number 10 corresponds to the length of the col dimension, or is the number of posions one needs to go to the next row in a one dimensonal array.

Now on to the fourth dimension. I'll give an example. But remember, arrays start counting at 0, so to get the length of a dimension one needs to add 1 to the upperbound.
(Warning, this code has not been tested.)
 Code:// These are the upperbounds of each dimensionconst int dim1=4, dim2=4, dim3=4, dim4=4;// This creates a four-dimensional arrayint myArray[dim1][dim2][dim3][dim4];// This writes a value to my array;myArray[1][2][3][4]=99;// This function translated a four dimensional address to a one-dimensional addressint fourToOne(int d4, int d3, int d2, int d1){  return d4*(dim4+1)*(dim3+1)*(dim2+1) +  d3*(dim4+1)*(dim3+1)+  d2*(dim4+1) +d1;} // This creates a one-dimensional array with the same sizeint myArray[forToOne(dim1,dim2,dim3,dim4];// This writes a value to my array;myArray[fourToOne(1,2,3,4)]=99;

_________________
My most recent blog: A grain of sugar

Tue Oct 21, 2008 4:38 pm
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Re: 4-dimensional arrays ?
very tricky, thanks a lot

Tue Oct 21, 2008 4:56 pm
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Re: 4-dimensional arrays ?
 Aswin wrote:There is a simpler solution to create a multidimensional array. The trick is to convert it to a one dimensional array. . . .

A furthur simplification is to write a small helper function (or macro) that does the array index calculation for you. It would have four parameters for a four dimensional array. The actual "index" calculation can be localized to the one helper function.

Tue Oct 21, 2008 5:08 pm
Rookie

Joined: Sat Apr 19, 2008 11:51 am
Posts: 43
Re: 4-dimensional arrays ?
hi,
I managed to built my table with an 2D array of a 2D structure type.
Thx to all!

Wed Oct 22, 2008 12:07 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 13 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.