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

Home » Public Forums » archive » Transpose of string along with float variable??
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
Transpose of string along with float variable?? [message #93906] Wed, 23 November 2016 03:08 Go to next message
Sapna Mishra is currently offline  Sapna Mishra
Messages: 66
Registered: December 2015
Member
Hello every one,

Can any one tell me how to print transpose of arrays which includes array of
string, float and integers together??

Eg. s=['dog','cat','monkey ' ]
n=[1,2,3]
x=[100.0,109.0,111.0]
when I am doing :
IDL> print,transpose( [ [n],[s],[x] ])
I get:

% Type conversion error: Unable to convert given STRING to Integer.
1 0 100
2 0 109
3 0 111
I want to print:
1 dog 100.0
2 cat 109.0
3 monkey 111.0

I know its just a small problem but I am using such things in my big complicated code.
Re: Transpose of string along with float variable?? [message #93907 is a reply to message #93906] Wed, 23 November 2016 03:38 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Wednesday, November 23, 2016 at 12:08:45 PM UTC+1, Sapna Mishra wrote:
> Hello every one,
>
> Can any one tell me how to print transpose of arrays which includes array of
> string, float and integers together??
>
> Eg. s=['dog','cat','monkey ' ]
> n=[1,2,3]
> x=[100.0,109.0,111.0]
> when I am doing :
> IDL> print,transpose( [ [n],[s],[x] ])
> I get:
>
> % Type conversion error: Unable to convert given STRING to Integer.
> 1 0 100
> 2 0 109
> 3 0 111
> I want to print:
> 1 dog 100.0
> 2 cat 109.0
> 3 monkey 111.0
>
> I know its just a small problem but I am using such things in my big complicated code.

Probably not what you were looking for, but how about this?

print,transpose( [ [string(n)],[string(s)],[string(x)] ])
1 dog 100.000
2 cat 109.000
3 monkey 111.000

Cheers,
Helder
Re: Transpose of string along with float variable?? [message #93908 is a reply to message #93907] Wed, 23 November 2016 03:48 Go to previous messageGo to next message
Sapna Mishra is currently offline  Sapna Mishra
Messages: 66
Registered: December 2015
Member
On Wednesday, November 23, 2016 at 5:08:48 PM UTC+5:30, Helder wrote:
> On Wednesday, November 23, 2016 at 12:08:45 PM UTC+1, Sapna Mishra wrote:
>> Hello every one,
>>
>> Can any one tell me how to print transpose of arrays which includes array of
>> string, float and integers together??
>>
>> Eg. s=['dog','cat','monkey ' ]
>> n=[1,2,3]
>> x=[100.0,109.0,111.0]
>> when I am doing :
>> IDL> print,transpose( [ [n],[s],[x] ])
>> I get:
>>
>> % Type conversion error: Unable to convert given STRING to Integer.
>> 1 0 100
>> 2 0 109
>> 3 0 111
>> I want to print:
>> 1 dog 100.0
>> 2 cat 109.0
>> 3 monkey 111.0
>>
>> I know its just a small problem but I am using such things in my big complicated code.
>
> Probably not what you were looking for, but how about this?
>
> print,transpose( [ [string(n)],[string(s)],[string(x)] ])
> 1 dog 100.000
> 2 cat 109.000
> 3 monkey 111.000
>
> Cheers,
> Helder

Ohhh this worked Thanku very very much!!!!!!!!!!!!!!!
Re: Transpose of string along with float variable?? [message #93911 is a reply to message #93908] Wed, 23 November 2016 09:11 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
Alternatively,

s=['dog','cat','monkey ' ]
n=[1,2,3]
x=[100.0,109.0,111.0]


for i = 0, n_elements(s)-1 do print, n[i], s[i], x[i], FORMAT='(i3, 2x, a6, 2x, f7.2)'
1 dog 100.00
2 cat 109.00
3 monkey 111.00
Re: Transpose of string along with float variable?? [message #93937 is a reply to message #93908] Thu, 01 December 2016 12:47 Go to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
Implicit in Helder's response is what cause your problem in the first place.

Arrays must be of the same variable type, so strings and floats cannot be in the same array.

Helder's solution cast the floats (and integers) as strings; now, we have all the same variable type (string) and they can be in an array.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: How to infer number of minor ticks?
Next Topic: write_png help

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

Current Time: Wed Oct 08 09:20:37 PDT 2025

Total time taken to generate the page: 0.00372 seconds