473,395 Members | 1,488 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,395 software developers and data experts.

How can i get each coloumn of a 2D array as 1D arrays??

hi everyone,
i have a problem. i have been using an FFT method for 1D arrays. now i
need to extend the code for 2D arrays..i thought it would be simple and
i managed to implement the FFT method for every row in the array..the
problem is now that i need to do the same for each of the
coloumns...and the elements shud not be copied into any other
arrays..because the FFT is to be applied on the original array...and
the same must be given as output..can anyone tell me how i could get
the coloumns each as a 1D array...?? i am including the int main()
here.
i'd be so thankful for the help.

int main(int argc, char *argv[])
{

double x1[][]={{2,3,4,5},{4,-1,2,3},{1,2,3,4}};
double y1[][]={{-1,0,2,0},{1,2,2,1},{0,0,0,0}};

cout << "\nInput: \n\n";
for (int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout << x1[i][j] << "+" << y1[i][j] <<"i \t";
}
cout<<"\n";
}
for(int i=0;i<3;i++)
{
// FFT method for each row

FFT(-1,2,x1[i],y1[i]);
}

/* for (int i=0;i<(sizeof(x1)/sizeof(x1[0]));i++)
cout << "Output: " << x1[i] << " + i " << y1[i] <<"\n";

//cout << x1[1] <<"\n";*/
cout<<"\nOuput: \n\n";
for (int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout << x1[i][j] << "+" << y1[i][j] <<"i \t";
}
cout<<"\n";
}

getch();
return 0;

}

Jan 28 '06 #1
2 1950
Renjini wrote:
hi everyone,
i have a problem. i have been using an FFT method for 1D arrays. now i
need to extend the code for 2D arrays..i thought it would be simple and
i managed to implement the FFT method for every row in the array..the
problem is now that i need to do the same for each of the
coloumns...and the elements shud not be copied into any other
arrays..because the FFT is to be applied on the original array...and
the same must be given as output..can anyone tell me how i could get
the coloumns each as a 1D array...?? i am including the int main()
here.
i'd be so thankful for the help.

int main(int argc, char *argv[])
{

double x1[][]={{2,3,4,5},{4,-1,2,3},{1,2,3,4}};
double y1[][]={{-1,0,2,0},{1,2,2,1},{0,0,0,0}};

cout << "\nInput: \n\n";
for (int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout << x1[i][j] << "+" << y1[i][j] <<"i \t";
}
cout<<"\n";
}
for(int i=0;i<3;i++)
{
// FFT method for each row

FFT(-1,2,x1[i],y1[i]);
}

/* for (int i=0;i<(sizeof(x1)/sizeof(x1[0]));i++)
cout << "Output: " << x1[i] << " + i " << y1[i] <<"\n";

//cout << x1[1] <<"\n";*/
cout<<"\nOuput: \n\n";
for (int i=0;i<3;i++)
{
for(int j=0;j<4;j++)
{
cout << x1[i][j] << "+" << y1[i][j] <<"i \t";
}
cout<<"\n";
}

getch();
return 0;

}


The following class might be useful to you:

//-----------------------------------------------------------------------------

#include <iostream>

template <typename T>
class ColArray {
public:
template <int N, int M>
ColArray(T (&arr)[N][M], int col) : _p(*arr + col), _sz(M) {}

T& operator[](int index) { return *(_p + index * _sz); }
const T& operator[](int index) const { return *(_p + index *
_sz); }

operator T*() { return _p; }

private:
T* _p;
int _sz;
};

int main()
{
int arr[3][3] = {{11, 12, 13},
{21, 22, 23},
{31, 32, 33}};

// Create a new 1D 'array' by passing the original 2D
// array and the column you want (counting from 0).
ColArray<int> col(arr, 2);

for (int i = 0; i < 3; i++)
std::cout << col[i] << std::endl;

return 0;
}

// Output:
// $ ./cols
// 11
// 21
// 31

//-----------------------------------------------------------------------------

I just wrote it now - it automates the task of adding the row size onto
the address of the first element in the column to reach the desired
index in the same column. Unfortunately I there's no way of doing this
more efficiently (that I can see of) given the constraints you
specified. You are going to take a hit calculating either the row or
column FFT because of the way arrays are ordered.

Anyway you should be able to pretend that a ColArray object is normal
array and pass it to your FFT function. If I've missed anything you can
add it to the class yourself - subscripting and array to pointer
decomposition was all I could think of off the top of my head.

To calculate the column FFT:

for (int i = 0; i < 3; i++) {
// FFT method for each row
FFT(-1, 2, ColArray(x1, i), ColArray(y1, i));
}

Hope that helps =)
Jan 28 '06 #2
Ben Radford wrote:
// Output:
// $ ./cols
// 11
// 21
// 31


I just realised that I posted the output for the first column. This
should be:

// $ ./cols
// 13
// 23
// 33

I hope there's no more mistakes in there.
Jan 28 '06 #3

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

Similar topics

2
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
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...
2
by: Karl Groves | last post by:
I have a rather long form (122 SETS of questions - don't worry, it is just me using it, lol) I have the questions set up as "Survey ID, Question ID, Answer, Impact, Comments", which I have set...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
5
by: Hermann.Richter | last post by:
These array functions: 'each', 'current', 'next', 'end' They return a reference or a value. let's say I want to modify the last value of an array without iterating through all of them. I...
2
by: YMPN | last post by:
Hello Guys, I have a datetime coloumn, i want to extract time only this coloumn and save this time only to another coloumn in the same table. I am new to asp.net.. thanks..
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower...
0
by: mantrid | last post by:
I was thinking along these lines initially but didnt know much about arrays. So thought the easiest way was to use two separate fields. However the two fields match, in that the commar separated...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.