changing the values
1 次查看(过去 30 天)
显示 更早的评论
i have values in
r as
'<=50k' '>50k' '>50k' ; ;
; '>50k'
now i want to replace these values
>50k as 1
<=50 as 0
please help
i read those values from excel sheet
[d r]=xlsread('mydata.xls');in whicg i got those values in r
0 个评论
采纳的回答
Andrei Bobrov
2012-2-25
in this case
r = {'<=50k' '>50k' '>50k' '>50k'}
[a n n] = unique(r)
k = {0,1}
rnew = k(n)
or
rnew = cellfun(@(x)x-'0',regexprep(r,{'<=50k' , '>50k'},{'0','1'}))
on FIR comment: try
rnew = regexprep(r,{'<=50k' , '>50k'},{'0','1'})
on Pat comment
r = {'<=50k' '>50k' '>50k' '>50k' 'fg' ''}
rnew = regexprep(r, {'<=50k', '>50k'}, {'0', '1'})
t = ismember(rnew, {'0', '1'})
rnew(t) = cellfun(@(x)x-'0', rnew(t), 'un', 0)
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!