Find the answer to your Linux question:
Results 1 to 3 of 3
I have to make a graph using bash and i have a weird thing going on. If i set the x and y indexes to 0 it will graph the ...
  1. #1
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99

    graphing in bash

    I have to make a graph using bash and i have a weird thing going on. If i set the x and y indexes to 0 it will graph the first point, however, if i try to increment them or change them to a different number it doesn't graph anything. The way i have it set up is a while loop that goes through the rows or y values and then a while loop inside of that goes through the x values. It is a 40 by 80 grid so those numbers are set. Here is the function that graphs. If anyone sees any errors as to why it would graph the first point ok, but then not any others, I would appreciate it. I know i am not incrementing the indexes anywhere because if i try that it doesn't graph anything. So i thought it was not graphing all the points because i wasnt incrementing the indexes right, but even if i set the indexes to 1 instead of 0 it won't graph the second point. Anyone see what i'm doing wrong?
    Code:
    function graph
    {
        rows=40
        cols=1
        yIndexA=0    #go through y array
        xIndexA=0    #go through x array
        #gMinX=$(echo "scale=5 ; $minX - $1" | bc)
       # gMaxY=$(echo "scale=5 ; $maxY + $2" | bc)
    
    ############################################################################
        #loop through y values
        while [ "$rows" -gt 0 ]
        do
          #gMaxY=$(echo "scale=5 ; ($gMaxY - $2)" | bc)
         # blankSpacesDown=$(echo "scale=5 ; (${yValues[yIndex]} - $gMaxY - 1)" | bc)
          #printSpacesDown $blankSpacesDown
          #echo -n ${yValues[yIndex]}
          #echo -n $gMaxY
    
          #(( yIndex++ ))
          echo
    
          # reset things for innner loop
          cols=1
          xIndexA=0
    
         ##########################################################################
         #loop through x values
         while [ "$cols" -lt 81 ]
         do
           #gMinX=$(echo "scale=5 ; ($gMinX + $1)" | bc)
           #blankSpaces=$(echo "scale=5 ; (${xValues[xIndex]} - $gMinX - $1)" | bc)
           #printBlankSpaces $blankSpaces
           #printBlankSpaces 4
            #echo -n ${convertedYValues[yIndex]} " "
            #echo -n ${convertedXValues[xIndex]} " "
            #varX=${convertedXValues[xIndex]}
            #varY=${convertedYValues[yIndex]}
            #echo -n $rows " "
            #echo -n $cols " "
    
           if [ "$cols" == "${convertedXValues[xIndexA]}" ]
           then
             if [ "$rows" == "${convertedYValues[yIndexA]}" ]
             then
               echo -n "X"
             fi
             else
               echo -n " "
           fi
           #echo -n ${xValues[xIndex]} " "
           #echo -n $gMinX
    
            #(( xIndex++ ))
           #(( yIndex++ ))
           (( cols++ ))
        done  # loop through x
        #(( yIndex++ ))
        (( rows-- ))
      done # loop through y
      echo
    
    }  # end graph function

  2. #2
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99
    i got it, the comparisons were wrong change them to -le for less than or equal to and make it 80 and then change it to -ge for greater than or equal to and make it 0. This will graph any point i put in. So if i make the indexes 1 then it will print the point at x array is 1 and y array is 1. Now i just have to figure out where to increment the indexes.

  3. #3
    Just Joined!
    Join Date
    Sep 2005
    Posts
    99
    got it you just have to increment the xIndex and yIndex inside of the if statement when a value is found

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...