comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Splitting An Array Of Strings Without Using Loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Splitting An Array Of Strings Without Using Loops [message #35875 is a reply to message #35864] Fri, 25 July 2003 06:38 Go to previous messageGo to previous message
darrick.white is currently offline  darrick.white
Messages: 7
Registered: January 2003
Junior Member
mchinand@midway.uchicago.edu (Mike Chinander) wrote in message news:<bT2Ua.33$Z4.10135@news.uchicago.edu>...
> In article <e5624c04.0307240935.7234e53@posting.google.com>,
> Darrick White <darrick.white@med.ge.com> wrote:
>> This is probably simple, but I'm having a time trying to figure it
>> out. I want to be able to split an array of strings without using
>> loops.
>>
>> Example:
>> dataPoints is an array of strings with N elements
>> The format of each element within dataPoints is "x:y1:y2:y3:yn". More
>> than likely, the data will be in the format of x:y".
>>
>> This array will become data points (the first element is always
>> considered the x coordinate): (x,y) = 1,23. In case of multiple
>> points (2:21:34:54), the data will look like: (2,21), (2,34), (2,54).
>>
>> I need a way to take:
>> dataPoints[0] = 1:23
>> dataPoints[1] = 2:32
>> dataPoints[2] = 3:30
>> dataPoints[3] = 4:45
>>
>>
>> and create
>> points[2,4]
>> 1 23
>> 2 32
>> 3 30
>> 4 45
>>
>> -Darrick
>
> For the simpler case of just 'x:y' pairs the following show work:
>
> IDL> data=['1:23','2:32','3:30','4:45']
>
> put it into one big string
>
> IDL> datajoin=strjoin(data,':')
>
> IDL> print, datajoin
> 1:23:2:32:3:30:4:45
>
> Then split it up and reform it into a two by four array
>
> IDL> dataint=reform(fix(strsplit(datajoin,':',/extract)),2,4)
> IDL> print, dataint
> 1 23
> 2 32
> 3 30
> 4 45
>
>
> Hope that helps,
>
> --Mike

Thanks for the reply. Yes, that works, and that's what I am doing
now. However, there may be cases when the data may look like this:
['1:23','2:32:43','3:30:54','4:45']

In this case, I would like the data formatted into a 3x4 array

1 23 NaN
2 32 43
3 30 54
4 45 Nan

This is where I'm having a little trouble.

Thanks
-Darrick
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Reading images from a socket
Next Topic: IDL editor that does text folding

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 06:04:40 PDT 2025

Total time taken to generate the page: 1.43958 seconds