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

Home » Public Forums » archive » help with appending strings
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
help with appending strings [message #89294] Thu, 14 August 2014 11:42 Go to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
Hi all

So far I was working with 1 pair of stings (total=2 strings) but now I need to work with 180 pairs (total=360 strings). I define my two strings as shown below:

1 = 'C:\Users\string1'
2 = 'C:\Users\string2'

procedure....

Because now I need to define 360 strings I was wondering if I can write a loop instead of defined this like this.

With thanks
Gina
Re: help with appending strings [message #89295 is a reply to message #89294] Thu, 14 August 2014 11:49 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
No loops necessary! Two ideas:

myStrArr = 'C:\Users\string' + strtrim(indgen(360), 2)
myStrArr = 'C:\Users\string' + string(indgen(360), FORMAT='(i03)')


The format keyword is used to ensure all numbers have 3 digits (i.e. 001), so that sorting them is easier.
Re: help with appending strings [message #89296 is a reply to message #89294] Thu, 14 August 2014 11:51 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Thursday, August 14, 2014 2:42:02 PM UTC-4, g.na...@gmail.com wrote:
> Hi all
>
>
>
> So far I was working with 1 pair of stings (total=2 strings) but now I need to work with 180 pairs (total=360 strings). I define my two strings as shown below:
>
>
>
> 1 = 'C:\Users\string1'
>
> 2 = 'C:\Users\string2'
>
>
>
> procedure....
>
>
>
> Because now I need to define 360 strings I was wondering if I can write a loop instead of defined this like this.

Yes you can. Try making an array of strings,
dirs = ['C:\Users\string1', 'C:\Users\string2', 'C:\Users\string3']

And then loop through the strings and operate on them.
for i = 0, n_elements(dirs)-1 do begin
dir = dirs[i]
;; operate on DIR
endfor

Craig
Re: help with appending strings [message #89297 is a reply to message #89294] Thu, 14 August 2014 12:06 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
My strings are csv files. I forgot to mention this before


1 = 'C:\Users\string1.csv'
2 = 'C:\Users\string2.csv'
Re: help with appending strings [message #89298 is a reply to message #89294] Thu, 14 August 2014 12:51 Go to previous messageGo to next message
g.nacarts is currently offline  g.nacarts
Messages: 148
Registered: November 2013
Senior Member
I tried what Matthew has suggest me but I have a problem. Because I need to visualize the string since it's an image I am using the tvscl command but it's not able to display the image because string expression is not allowed. I tried to convert the string array to numeric using the double like this myStrArr = double(myStrArr) but I got the following error: Type conversion error: Unable to convert given STRING to Double.
Re: help with appending strings [message #89300 is a reply to message #89298] Thu, 14 August 2014 17:16 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Thursday, August 14, 2014 2:51:43 PM UTC-5, g.na...@gmail.com wrote:
> Because I need to visualize the string since it's an image

This doesn't make any sense. String is a particular variable type. Image (typically some sort of 2d numeric array) is a different variable type. (OK, OK, so it could be 3d....)

Further, trying to cast a string to double, in general, doesn't work. (Unless the string is a number of course.)

TVSCL takes a 2d array. So, a string wouldn't work - wrong variable type. You can't "visualize" a string in this way. Perhaps what you mean is the data in the files (the strings) have 2d data?

If so, you need to actually read in the data. I'm guessing you want something along the lines of READ_CSV, READCOL, etc. You'll manipulate the output to make a 2d array.

Craig's post gives a clue how to do this. ("operate on DIR"). This is where you would read in the data, for each string (file).
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Is it possible to speed up the Interpolate command?
Next Topic: error with struct expression

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

Current Time: Wed Oct 08 13:48:55 PDT 2025

Total time taken to generate the page: 0.00502 seconds