Nominal to useful without changing values
조회 수: 1 (최근 30일)
이전 댓글 표시
Part of my dataset is imported from an excel file, and several variables (with numeric values) were imported as cell strings. I need to convert the variable type to double so that I can run correlations with other variables.
I can convert to nominal type, but when I try to convert to a double or number (e.g. with 'double' or 'mat'), the values change (some becoming less than half of original value). Is there a way that I can convert the variable type while keeping the value of the variable for each observation, or do I need to re-import all of my data from excel one column at a time?
댓글 수: 0
답변 (2개)
Oleg Komarov
2012년 8월 14일
a = '23';
str2num(a)
str2double(a)
댓글 수: 2
Oleg Komarov
2012년 8월 14일
a = {'23','33'; '12','1'};
cellfun(@str2num,a)
str2double(a)
Both approached work, I would go for str2double.
Azzi Abdelmalek
2012년 8월 14일
편집: Azzi Abdelmalek
2012년 8월 14일
here an example:
A={'12' '45';'77' '15';'87' '524'} %your cell array
result=cellfun(@(x) str2num(x),A)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!