MATLAB Answers

How can I replace numbers in a vector by text ?

11 views (last 30 days)
Diego
Diego on 1 Jun 2014
Commented: Diego on 2 Jun 2014
Hi everybody!
I have a column in a csv file with 0 and 1 and I want to replace all the 0 values by FALSE and all the 1 values by TRUE. Anybody knows how can I do that? Thanks in advance!
I have been trying to do this but it doesn't work.
s(s==0)='FALSE'

  0 Comments

Sign in to comment.

Answers (1)

dpb
dpb on 1 Jun 2014
s(s==0)='text';
won't work because you're trying to change datatypes piecewise in an array.
SOTOO,
>> s=rand(10,1)>0.5;
>> v={'t';'f'};t=v(s+1)
t =
't'
'f'
't'
't'
'f'
'f'
'f'
't'
'f'
't'
>>

  8 Comments

Show 5 older comments
dpb
dpb on 2 Jun 2014
That's what I was at least trying to say IA; you can put them in a mixed cell, but as different cell elements, not within a single cell--that doesn't work.
And, yes, I misspoke on the meaning the new table -- I don't have it so wasn't sure of it's facilities.
Star Strider
Star Strider on 2 Jun 2014
Oh. OK. Thought I’d been behind the door again.
Know about ‘table’ but haven’t used it much yet.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!