473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Converting a multidimensional array to 2 single dimensional arrays

I have a multidimensional array defined as
private double[,] myArray = new double[ 2, 1024];
The first column of the array contains X values, the other contains Y values
I have a charting function defined as
Add(Array XValues, Array YValues)

How do I call the Add function, passing my array columns please.

thanks
Nov 16 '05 #1
3 8173
Hi,

Can you use jagged arrays (i.e. arrays of arrays), i.e. can you alter the
definition of your multidimensional array into "private double[][] myArray"
? With jagged arrays you can get the columns (rows) at once. See for an
example on
http://msdn.microsoft.com/library/de...ysTutorial.asp

Regards,
Bart

--
http://www.xenopz.com
"Claire" <cc@hotmai1.com> wrote in message
news:39*************@individual.net...
I have a multidimensional array defined as
private double[,] myArray = new double[ 2, 1024];
The first column of the array contains X values, the other contains Y
values
I have a charting function defined as
Add(Array XValues, Array YValues)

How do I call the Add function, passing my array columns please.

thanks

Nov 16 '05 #2
Your data is fundamentally in the wrong storage format to be amenable to
that Add() method.

You can do two things here. One, do like the other person said and change
from a 2-d array, double[,], to an array-of-arrays double[][]. The other is
to create temporary arrays containing the columns just for the purpose of
the Add() call:

double XValues[] = new double[1024];
double YValues [] = new double[1024];
for(int i =0; i < 1024, i++) {
XValues[i] = myArray[0,i];
YValues[i] = myArray[1,i];
}
Add(XValues, YValues);

If this is an isolated situation and it really is better for the rest of
your program to have the data in a true 2-d array, then I'd go with this
solution. But if you need to access the columns like that in many places,
then you're probably better off changing your data structure as the other
person described.
"Claire" <cc@hotmai1.com> wrote in message
news:39*************@individual.net...
I have a multidimensional array defined as
private double[,] myArray = new double[ 2, 1024];
The first column of the array contains X values, the other contains Y
values
I have a charting function defined as
Add(Array XValues, Array YValues)

How do I call the Add function, passing my array columns please.

thanks

Nov 16 '05 #3
My advice all depends upon what you plan to do with the X and Y values,
but you are doing charting, then I wonder why you aren't using the
System.Drawing.Point structure and making an aggregate of that:

class MyClass
{
private ArrayList coordinates = new ArrayList();

public void Add(double[] XValues, double[] YValues)
{
int coordinateCount = Math.Min(XValues.Length, YValues.Length);
for (int i = 0; i < coordinateCount; i++)
{
this.coordinates.Add(new Point(XValues[i], YValues[i]));
}
}
}

If you do things this way, you can do this:

Point aPoint = (Point)this.coordinates[i];

and then aPoint.X and aPoint.Y rather than remembering that index 0 is
X and index 1 is Y.

In .NET V2.0, which has generics, you can declare:

private List<System.Drawing.Point> coordinates = new
List<System.Drawing.Point>();

and then you can collapse the reference down to one line:

this.coordinates[i].X or this.coordinates[i].Y

Anyway, maybe not what you're after, but something to think about. :)

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TLOlczyk | last post by:
I have a brain cramp and I need some help. I have a chunk of code below which demonstrates a problem I have with multidimensional arrays. I want to keep it simple but something specific is...
2
by: Terry | last post by:
Hi, can someone plz tell me how multidimensional arrays (like a 2-D array) are stored in memory? Are they like single dimensional arrays? Stored sequentially in one "row", so to say? Thanks ...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
5
by: whisper | last post by:
Hi: there is an issue that confuses me and the FAQ did not clarify it for me. (Sorry I am just learning!) Let say I define a multidimensional array in my main routine as follows: int...
1
by: @ nospam.com | last post by:
Hi, If Im using Jagged arrays, the following is possible: int arr = new int for(int i=0; i<10; i++) { arr = new int; }
8
by: ais523 | last post by:
I've checked the FAQ for this and couldn't find the answer. Is the following code snippet portable? int a; a=6; printf("%d\n",(*a)); This prints "6" on my compiler. I've been told it's...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.