mien Posted June 29, 2009 Share Posted June 29, 2009 hi...can someone teach me how to find min and max value from text file....thanks.. Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 29, 2009 Share Posted June 29, 2009 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)) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 29, 2009 Share Posted June 29, 2009 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) Quote Link to comment Share on other sites More sharing options...
fuccaro Posted June 30, 2009 Share Posted June 30, 2009 After you get the atoms in the list LST: (eval (cons 'max LST)) Quote Link to comment Share on other sites More sharing options...
Freerefill Posted June 30, 2009 Share Posted June 30, 2009 After you get the atoms in the list LST:(eval (cons 'max LST)) o.o Slick solution, very nice! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 30, 2009 Share Posted June 30, 2009 After you get the atoms in the list LST:(eval (cons 'max LST)) I like it Quote Link to comment Share on other sites More sharing options...
dilan Posted July 31, 2019 Share Posted July 31, 2019 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) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 1, 2019 Share Posted August 1, 2019 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)) 1 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 1, 2019 Share Posted August 1, 2019 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. 1 Quote Link to comment Share on other sites More sharing options...
dilan Posted August 1, 2019 Share Posted August 1, 2019 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. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted August 2, 2019 Share Posted August 2, 2019 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 Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 5, 2019 Share Posted August 5, 2019 I use this style of min/max point list search a lot: (apply 'max (mapcar 'car lst)) -David Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.