Results 1 to 2 of 2
How do i use the bc command to do a few floating point calculations. I need it to find the scale for the x and y axis for a graph ...
- 04-03-2007 #1Just Joined!
- Join Date
- Sep 2005
- Posts
- 99
using bc and a few other things
How do i use the bc command to do a few floating point calculations. I need it to find the scale for the x and y axis for a graph i have to make. Here is what i have so far the bc part is at the very bottom. The subtraction part works, however, when i try to divide i get a "syntax error line 1, teletype" is the error i get. Can someone tell me how to subtract the max from the min and then divide by 80 and then store it in the variable xScale? Thanks
Code:#!/usr/bin/bash touch Xpoints touch Ypoints varX=0; while [ "$varX" != "" ] do echo "Enter an X value or a blank space to end input: " read varX; if [ "$varX" == "" ] then break; else xValues[i]=$varX; echo $varX >> Xpoints fi echo "Enter a Y value: " read varY; yValues[i]=$varY; echo $varY >> Ypoints (( i++ )) done size=${#xValues[*]} echo $size i=0 #while [ "$i" < "$size" ] #do #echo ${xValues[$i]} #(( i++ )) #done #sort to find maxX, minX, maxY, minY minX=`sort -g Xpoints | head -1` echo $minX maxX=`sort -g Xpoints | tail -1` echo $maxX minY=`sort -g Ypoints | head -1` echo $minY maxY=`sort -g Ypoints | tail -1` echo $maxY #!/usr/bin/bash touch Xpoints touch Ypoints varX=0; while [ "$varX" != "" ] do echo "Enter an X value or a blank space to end input: " read varX; if [ "$varX" == "" ] then break; else xValues[i]=$varX; echo $varX >> Xpoints fi echo "Enter a Y value: " read varY; yValues[i]=$varY; echo $varY >> Ypoints (( i++ )) done size=${#xValues[*]} echo $size i=0 #while [ "$i" < "$size" ] #do #echo ${xValues[$i]} #(( i++ )) #done #sort to find maxX, minX, maxY, minY minX=`sort -g Xpoints | head -1` echo $minX maxX=`sort -g Xpoints | tail -1` echo $maxX minY=`sort -g Ypoints | head -1` echo $minY maxY=`sort -g Ypoints | tail -1` echo $maxY nbrCol=80 #find the original scale #xScale=`echo "scale=5 ; $maxX - $minX" | bc` xScale=`echo "scale=5 ; $maxX - $minX" | bc` echo $xScale xScale=`echo "scale=5 ; xScale//80" | bc` echo $xScale
- 04-04-2007 #2Just Joined!
- Join Date
- Sep 2005
- Posts
- 99
well i figured out how to use bc to get that value. Now onto the other things part of the subject. I have to be able to store the values in arrays as they are read in. I want to do this with array[i] but i can not figure out how to get it to store it at the next i every time. Anyone know the syntax for this? Here is the part of the code i am looking at now:
I need to store the y values in yValues variable and store the x values in the xValues variable at index i. Anyone know how to do this? ThanksCode:varX=0; while [ "$varX" != "" ] do echo "Enter an X value or a blank space to end input: " read varX; if [ "$varX" == "" ] then break; else xValues[i]=$varX; echo $varX >> Xpoints fi echo "Enter a Y value: " read varY; yValues[i]=$varY; echo $varY >> Ypoints (( i++ )) done
*** EDIT ***
Nevermind i got it. It just took some looking


Reply With Quote