replace number by string
이전 댓글 표시
I have a vector with numeric values and I would like to replace the number in a given cell by a string (data are attached). For instance, 23=BDHE, 9997=BEIS, 11=CUAL, 4=CTGB, 60=MYMU, 1010=INJP, 3006=YNTA, and 80=TRQO. Thanks in Advance.
채택된 답변
추가 답변 (1개)
Jos (10584)
2015년 4월 10일
% conversion rules V(k) corresponds to S(k):
V = [ 3 4 6 9 1] ;
S = {'AA','B','CCC','D','EEE'} ;
ValuesIn = [3 6 4 6 3 1 9 9 0 4 4 1 3] % note the 0!
% engine to convert ValuesIn to StrOut
StrOut = repmat({'Unknown'},size(ValuesIn)) ;
[tf, idx] =ismember(ValuesIn, V) ;
StrOut(tf) = S(idx(tf))
카테고리
도움말 센터 및 File Exchange에서 Data Manipulation and Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!