Jump to content

Recommended Posts

Posted

hi...can someone teach me how to find min and max value from text file....thanks..

Posted

Depends on the format of the text file, but your code would probably look something like this:

 

(setq fileID "path\\filename.txt" linLst '())
(setq file (open fileID "R"))
(while (setq line (read-line file))
 (setq linLst (cons line linLst))
 )
(close file)

(setq maxNum (apply 'max linLst))
(setq minNum (apply 'min linLst))

Posted

May need a few "distof"'s in there...

 

(if (setq file (getfiled "Select File" "" "txt" )
 (progn
   (setq file (open file "r"))
   (while (setq nl (read-line file))
     (setq lst (cons (distof nl) lst)))
   (close file)

   (apply 'max lst)
   (apply 'min lst)

Posted

After you get the atoms in the list LST:

(eval (cons 'max LST))

Posted
After you get the atoms in the list LST:

(eval (cons 'max LST))

 

o.o Slick solution, very nice!

Posted
After you get the atoms in the list LST:

(eval (cons 'max LST))

 

I like it :D

  • 10 years later...
Posted

And how to do the same with the list? Choose a coordinate from the list with a minimum and maximum value of Z.

List:

((76751.7 53561.3 765.102) (76751.7 53561.3 765.102) (76758.6 53565.1 767.424) (76750.7 53565.9 766.755))

minimum:

(76751.7 53561.3 765.102)

maximum

(76758.6 53565.1 767.424)

 

Posted

You can sort a list on the z value caddr. look at 1st entry and last

 

;sort on x

(setq lst
 (vl-sort co-ordsxy
 (function (lambda (e1 e2)
 (< (car e1) (car e2)))
 )
 )
)

 

;sort on z

(setq lst
 (vl-sort co-ordsxy
 (function (lambda (e1 e2)
 (< (caddr e1) (caddr e2)))
 )
 )
)

 

(setq minz (nth 0 lst))

(setq maxz (nth (- (length lst) 1) lst))

  • Like 1
Posted

Sorting is inefficient when only an extremum is required.

 

You may find existing functions covering this operation here and a function specific to finding the minimum/maximum Z-coordinate here.

  • Like 1
Posted
9 hours ago, Lee Mac said:

Sorting is inefficient when only an extremum is required.

 

You may find existing functions covering this operation here and a function specific to finding the minimum/maximum Z-coordinate here.

Thank you very much, Lee Mac.

Posted

Nice Lee as usual did not even think about iterate over list check max min. Easy to add a couple more conds and make a library routine for min max X Y Z

Posted

I use this style of min/max point list search a lot:

 

(apply 'max (mapcar 'car lst))

 

-David

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...