Transpose of string along with float variable?? [message #93906] |
Wed, 23 November 2016 03:08  |
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   |
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   |
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   |
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  |
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.
|
|
|