Jump to content

Recommended Posts

Posted

Hi,

 

I have a string that I obtain from excel (0.0 1.2 1.2 1.2),

 

I can convert that to a list so that it is ("0.0" "1.2" "1.2" "1.2")

 

how can I convert it that each string in the list is actually a real number?

I thought I could use the "foreach" function combined with atof but I cannot seem to get it to work.

 

any ideas?

 

thanks

Posted

If you wish to use foreach function , here is an example .

 

(foreach x '("0.0" "1.2" "1.2" "1.2")
 (setq l (cons (read x) l))
 )
(reverse l)

Posted
I have a string that I obtain from excel (0.0 1.2 1.2 1.2)

Please don't miss that what you have listed there is a list, not a string. A string will look like:

"0.0 1.2 1.2 1.2"

And you will need to split it by spaces and after use ATOF or DISTOF to convert in real numbers.

Posted

Hi,

 

That is giving me an error. see below code.

 

 


(setq dist_list (getcell "I10"))

 
 (setq dist_list (sinc:String->List dist_list " "))

 
(foreach x dist_list
 (setq dist_list1 (cons (read x) dist_list))
 )
(reverse dist_list1)




(print dist_list1)

 

(1.2 "0.0" "1.2" "1.2" "1.2") Fehlerhafter Argumenttyp: numberp: "0.0"

Posted

Maybe , check it out

 

 


 (setq dist_list1 (cons (read x) dist_list[color=red]1[/color]))
 

Posted

I have used this from another forum by pbejse!

 

(mapcar 'Read dist_list)

Posted
I have used this from another forum by pbejse!

 

The majority of talent users have accounts in all around forums , so if you post your question all around the forums , you'd get and see the same users with the same answer mostly .

Posted
(setq dist_list (getcell "I10"))
(setq dist_list (sinc:String->List dist_list " "))
(foreach x dist_list
 (setq dist_list1 (cons (read x) dist_list))
)
(reverse dist_list1)
(print dist_list1)

 

You can skip a few steps:

(read (strcat "(" (getcell "I10") ")"))

Posted

..(setq dist_list (getcell "I10"))
(setq dist_list (sinc:String->List dist_list " "))...... 

 

The OP and i never got that far on the other forum :D,

 

I guess it depends on the getcell or sinc:String->List subfunction feargt is using. as you can see from the "error"

 

(1.2 "0.0" "1.2" "1.2" "1.2") Fehlerhafter Argumenttyp: numberp: "0.0"

 

Somewhere along the way, one of the element ended up as a real number.

 

You can skip a few steps:

(read (strcat "(" (getcell "I10") ")"))

 

Then yes, Lee's suggestion to skip conversion of cell value to string and then back makes sense.

Posted

(read (strcat "(" (getcell "I10") ")"))

 

the above was actually originally posted by Lee-MAc

 

Thanks for all the replies on this. I will try this one out later today.

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...