changing the values

1 回表示 (過去 30 日間)
FIR
FIR 2012 年 2 月 25 日
編集済み: Azzi Abdelmalek 2013 年 10 月 25 日
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

採用された回答

Andrei Bobrov
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 件のコメント
FIR
FIR 2012 年 2 月 25 日
Andrei error in both
in first i get values more than 1
and in second is get error aS
Error using ==> cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Pat
Pat 2012 年 2 月 25 日
it works,but i want that single quotes to be removed for further processing

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by