View Single Post
Old Feb 21, 2013, 12:57 PM   #10
Aquinus
3500 Posts
 
Aquinus's Avatar
 
Join Date: Jan 2012
Location: Dover, New Hampshire, USA
Posts: 4,234 (8.87/day)
Thanks: 1,259
Thanked 1,315 Times in 977 Posts

System Specs

Quote:
Originally Posted by ste2425 View Post
quick question i have a multidimensional array which is storing my fft results over time each column being the results from the fft. Now ive seen a swap function which can transfer the data from one array to another but is there a function to shift the columns down when i wish to enter the latest fft result? So say the no of columns is 5. data from column index 4 will be shifted to 3, 3 shifted to 2, 2 shifted to 1, 1 shifted to 0 and the data that was originally in 0 deleted leaving column 4 empty or at least filled with what ever it puts there ready for me to fill it with my fft results?

It would make life easier if there was a function to do this, if not i can easily make up a little function to do so.
Quote:
Originally Posted by Fourstaff View Post
Just write a loop sending 5 to 4, 4 to 3, 3 to 2 and 2 to 1, and then add data to 5th column. Use While loop, sometimes faster. As long as array dimensions does not change it will be done in no time.

Edit: Or you can write a function sending 2:5 to 1:4, and then input a new 5, doing away with a silly loop
I agree with Fourstaff but it be helpful to know what you're trying to do (mathematically,) when you're shifting this away. I'm trying to conceptualize what you're doing and I'm having a hard time putting all of it together which will render any recommendation I make partially moot.

So if you had a multi-dim array like this:
Code:
[ A, B, C ]
[ D, E, F ]
[ G, H, I ]
We will call this array N.
When I refer to array indices the top left is 0,0 with the top right being 2,0. (Think x and y)

You want to transform it in a way where array N has its elements shifted so elements get moved from (x, y) => (x-1, y-1) where x > 0 and y > 0.

So you maybe want something like this?

Code:
void shift(int x, int y, int * arr) {
    int xc, yc;

    // The corners go to zero since nothing can ever be moved into them.
    *(arr + (x - 1)) = 0;
    *(arr + (y * (x - 1))) = 0;

    // Start at 1,1. The first place an element will get moved to another place
    // in the array.
    for(yc = 1; yc < y; yc++) {
        for(xc = 1; xc < x; xc++) {
            *(arr + ( (yc - 1) * x ) + (xc - 1)) = *(arr + (yc * x) + xc);
            if( (xc + 1) >= x | (yc + 1) >= y) {
                // New values go here, zero them out for now.
                *(arr + (yc * x) + xc) = 0;
            }
        }
    }
I made a quick little C application to try it out and it does this. The first table output it the array before shift is called and the second is after.

Code:
~$ ./a.out
---- START TABLE ----
[  1804][   846][  1681][  1714][  1957]
[   424][   719][  1649][   596][  1189]
[  1025][  1350][   783][  1102][  2044]
[  1967][  1365][  1540][   304][  1303]
[    35][   521][   294][  1726][   336]
----- END TABLE -----
---- START TABLE ----
[   719][  1649][   596][  1189][     0]
[  1350][   783][  1102][  2044][     0]
[  1365][  1540][   304][  1303][     0]
[   521][   294][  1726][   336][     0]
[     0][     0][     0][     0][     0]
----- END TABLE -----
I hope this is helpful. It's been quite some time since I've written some C.
__________________
MyHeat
Aquinus is online now  
Crunching for Team TPU
Reply With Quote
The Following User Says Thank You to Aquinus For This Useful Post: