convert number in "*"

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

convert number in "*"

turbofib
hi,

 f=[0 1 0 0 1 1]
f =

   0   1   0   0   1   1

i want to convert  0 in nan and 1 in *

ans=[ nan * nan  nan * * ]

it's possible to do this?

   



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: convert number in "*"

PhilipNienhuis
turbofib wrote

> hi,
>
> f(f == 0) = NaN
> f =
>
>    0   1   0   0   1   1
>
> i want to convert  0 in nan and 1 in *
>
> ans=[ nan * nan  nan * * ]
>
> it's possible to do this?

Not literally as you start with a strictly numeric array (as you have square
brackets around it) and want to convert it to an array containing strings
("*"). That is only possible with cell arrays.
As an example the next sequence of commands:

f(f == 0) = NaN
f = num2cell (f)
f = f(cellfun (@isfinite, f)) = "*"

will do but undoubtedly there will be faster and more efficient ways.
You *can* do

f(f == 0) = NaN
f(f == 1) = "*"

but you'll end up  with

f =
   NaN    42   NaN   NaN    42    42

where 42 equals uint8 ("*")


Philip



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: convert number in "*"

nrjank
 
> i want to convert  0 in nan and 1 in *
>
> ans=[ nan * nan  nan * * ]
>
> it's possible to do this?


It really depends on what class of output you want.

That mixes numbers and characters. So you could convert to a character array using different string manipulations, and substitute * and NaN for 1 and 0 in the char array.  or as Phillip mentioned, a cell array would do it.  

So the answer is, what is it you are really trying to do?


Reply | Threaded
Open this post in threaded view
|

Re: convert number in "*"

turbofib
hi nrjank

i need to write this simbol in Excel (i need to convert this output in
symbol to write it)




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html