LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array sorting by formula node

Solved!
Go to solution

Hi, everyone, I want to use the formula node to sort one array with small to large value order, e.g 16,2,1,5,3, then the result should be 1,2,3,5,6.

 

then my program is like this, but I cannot get the corret answer. Please help me. Thank you very much.untitled.JPG

Working...
0 Kudos
Message 1 of 9
(4,832 Views)

I hate to break it to you, but you are re-inventing the wheel.

 

sort.png

Use the Sort function in the Array palette to achieve what you are trying to do.

Cory K
0 Kudos
Message 2 of 9
(4,824 Views)

Hi, the function you shown up is what I know before.

Now I am just trying to practise the formula node, but it can not work, could you help me to work on the formula node? Thank you very much for your reply....

 

 

Working...
0 Kudos
Message 3 of 9
(4,818 Views)
Yes, I can help you out with your text programming Smiley Mad , let me look over your formula node quickly.
Cory K
0 Kudos
Message 4 of 9
(4,814 Views)

It is so kind of you to give me the help....:womanvery-happy:

By the way, I checked the code in Dev-CPP softwar, it works, but here is strange.

Message Edited by McArthur on 06-25-2009 03:19 PM
Working...
0 Kudos
Message 5 of 9
(4,806 Views)
I have it like this sometimes my self. Sometimes I need a breakpoint. But then I prefer doing it in Assembly language. Just for fun I toy with a Microchip CPU. For a short time I can feel the joy and rush of taking a chunk of memory and do whatever I like without going through some sort of memory management. Perhaps it reflects my daily situationSmiley Very Happy


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 6 of 9
(4,800 Views)
It is really difficult to get the answer, I am still hung on it.
Working...
0 Kudos
Message 7 of 9
(4,791 Views)
Solution
Accepted by McArthur

McArthur,

 

You are probably getting an array of zeros because you are iterating the inner loop one to many times.  Change line 9 to "for(j=0;j<(sizeArr-1);j++)".  This should give you correct numbers.

 

Having said that, this algorithm is very inefficient (O(n^2)).  I would suggest simply using the native "Sort 1D Array" primitive.

 

Chris M 

0 Kudos
Message 8 of 9
(4,788 Views)

Ha, Thank you very much. you solve my stupid error...

But still strange that I can compile and run them in the Dev-CPP.

like:

#include <stdio.h>
#include <stdlib.h>
#define sizeArr 5

int main(int argc, char *argv[])
{
  int inArr[sizeArr]={6,1,4,5,0};
  int *ii=inArr;
  int i=0;
  int j=0;
  int temp=0;

  for (i=0;i<sizeArr;i++)
  {
   for(j=0;j<sizeArr;j++)
   {
         if (inArr[j]>=inArr[j+1])
         {
              temp=inArr[j+1];
              inArr[j+1]=inArr[j];
              inArr[j]=temp;
         }
   }
  }
  printf("Hello\n");
  for(i=0;i<sizeArr;i++)
  {
     printf("%d\n",inArr[i]);                   
  }
 
  system("PAUSE");   
  return 0;
}

 

What I got is:

 

untitled.JPG

Working...
0 Kudos
Message 9 of 9
(4,783 Views)