From rpv25 at unh.edu Thu Jun 9 13:10:22 2011 From: rpv25 at unh.edu (Ronak Bhatia) Date: Thu, 9 Jun 2011 16:10:22 -0400 Subject: [Yorick-users] How do I convert from a string to an integer? Message-ID: Hi. I've been converting .mat files to ascii text files using dlmwrite in matlab and then trying to read it into yorick using strtok(). It worked but all of the data are integers but are being read in as strings. So I have these long array of strings of integers. Ex. ["0","1","2","3","4"]; but I cannot use the integers at all because they are strings. Is there any way I can convert these string arrays? Also, when I use strtok() and I supply it with a value more than the number of values delimited, it sends me back an array with (nil) in it. >str = "0,1,2,3,4"; >str2 = strtok(str, ",", 6); >str2 ["0","1","2","3","4",(nil)]; and I'm not even sure how to check for a (nil) element because an if statement yields false. >str2(6) (nil) >str2(6) == (nil) 0 What can I do? Thank you, Ronak -------------- next part -------------- An HTML attachment was scrubbed... URL: From FRigaut at gemini.edu Fri Jun 10 12:10:05 2011 From: FRigaut at gemini.edu (Francois Rigaut) Date: Fri, 10 Jun 2011 19:10:05 +0000 Subject: [Yorick-users] How do I convert from a string to an integer? In-Reply-To: References: Message-ID: <1F32DC5F-7537-4B5F-8081-FCA9E7408FF7@gemini.edu> Hi Ronak, Typically, I think it would be better to use the forum for that kind of question. But there you are, so let me try to answer. The best way to read matlab files in yorick is probably to use the ml4 plugin. I've been using it for years for a production yorick package, and it works well. It only reads matlab4 format, so write it with the "-v4" option from matlab. use ml4scan,file_name to see what's in there and var=ml4read(file_name,variable_name) to read a variable. as far as reading data from a file, the easiest is probably to use rdcols.i, which I attach. Cheers, Francois -------------- next part -------------- A non-text attachment was scrubbed... Name: rdcols.i Type: application/octet-stream Size: 10584 bytes Desc: rdcols.i URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT00001.txt URL: