Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

convert logical to string

397 views
Skip to first unread message

maan

unread,
Mar 4, 2012, 6:43:15 PM3/4/12
to
A=0 1 1 1 0 1 1 0 ;
A is of type logical
i need to convert it to a string , so A will equal 'v'

maan

unread,
Mar 4, 2012, 6:49:13 PM3/4/12
to
"maan " <maan_...@yahoo.com> wrote in message <jj0umi$pi4$1...@newscl01ah.mathworks.com>...
> A=0 1 1 1 0 1 1 0 ;
> A is of type logical
> i need to convert it to a string , so A will equal 'v'


i use matlab R2009a

Roger Stafford

unread,
Mar 4, 2012, 6:54:12 PM3/4/12
to
"maan " <maan_...@yahoo.com> wrote in message <jj0umi$pi4$1...@newscl01ah.mathworks.com>...
> A=0 1 1 1 0 1 1 0 ;
> A is of type logical
> i need to convert it to a string , so A will equal 'v'
- - - - - - - -
What do you want the string content to be? FTTTFTTF, 01110110, or what? It would be whatever the 'v' array contains that you referred to.

Roger Stafford

maan

unread,
Mar 4, 2012, 7:06:12 PM3/4/12
to
"Roger Stafford" wrote in message <jj0vb4$r99$1...@newscl01ah.mathworks.com>...
i have an xor result=01110110 , so i need to convert that result to Character ,,

so how to convert a logical vector to string of character ?? thank you

maan

unread,
Mar 4, 2012, 7:10:17 PM3/4/12
to
"Roger Stafford" wrote in message <jj0vb4$r99$1...@newscl01ah.mathworks.com>...
another explain and i hope you will understand what i want

i need to convert logical vector to string .. so i can take each 8 bits of the logical
vectors and convert it to it's equevilant of char ..


A=0 1 1 1 0 1 1 0 1 1 0 0 0 0 1 ;
A is of type logical
i need to convert A to a string , so the string will equal = va

Eduardo Montoya

unread,
Mar 4, 2012, 8:10:13 PM3/4/12
to
"maan " <maan_...@yahoo.com> wrote in message <jj1099$p2$1...@newscl01ah.mathworks.com>...
Must be a better way, but..

From string:

v = '01110110'
a = '01100001'
A = [v a]

tostring = @(x)char(bin2dec(reshape(x,8,prod(size(x))/8)'))'
tostring(A)

v = cast([0 1 1 1 0 1 1 0],'logical')
a = cast([0 1 1 0 0 0 0 1],'logical')
A = [v a]

tostring = @(x)char(sum(bsxfun(@times,(2.^[7:-1:0]),reshape(x,8,prod(size(x))/8)'),2))'
tostring(A)

maan

unread,
Mar 4, 2012, 9:03:12 PM3/4/12
to
"Eduardo Montoya" wrote in message <jj13pl$a64$1...@newscl01ah.mathworks.com>...
Thank you very very very much ,, iam very glad now ,, thank you you were very helpful for me
0 new messages