How can I replace numbers in a vector by text ?

조회 수: 5 (최근 30일)
Diego
Diego 2014년 6월 1일
댓글: Diego 2014년 6월 2일
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'

답변 (1개)

dpb
dpb 2014년 6월 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
Star Strider
Star Strider 2014년 6월 2일
Oh. OK. Thought I’d been behind the door again.
Know about ‘table’ but haven’t used it much yet.
Diego
Diego 2014년 6월 2일
Thanks for your helpful!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by