How can I replace numbers in a vector by text ?

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'

Answers (1)

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

It works perfectly, but my problem now is that I have to represent this column (cell) with other columns that they are double format. I use cell2mat to convert cell format to double format but it doesn't work.
The problem is that the cell is composed for char values.
Say What????
You can't hold character and numeric data in the same array...if it's a cell array, it'll have to hold a column that's char and another that is numeric in the cell array as two cells.
Show in a sample code snippet what you're trying to do precisely, but sounds like it's an attempt at the impossible. Oh, there's the new datafun object that can mix metaphors if you've got a very recent version. Maybe that'd solve the problem...
Fascinated by the possibility, I did a search of the online documentation and couldn’t find any ‘datafun’ object. There’s a datafun directory but nothing else.
Where didn’t I look?
Not sure I understand what dpb's saying. You can hold numbers and strings in a cell array and they don't need to be all the same across rows or columns. Here's proof:
a{1,1} = 1;
a{2,1} = 'Hello World!';
a{1,2} = 'MATLAB';
a{2,2} = 22
I think he was referring to a "table" which is a new object (rather than datafun), and for a table, everything in a column must be the same data type (all numbers or all strings).
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.
Oh. OK. Thought I’d been behind the door again.
Know about ‘table’ but haven’t used it much yet.
Thanks for your helpful!

Sign in to comment.

Categories

Asked:

on 1 Jun 2014

Commented:

on 2 Jun 2014

Community Treasure Hunt

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

Start Hunting!