Nominal to useful without changing values

1 visualización (últimos 30 días)
Jordan
Jordan el 14 de Ag. de 2012
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?

Respuestas (2)

Oleg Komarov
Oleg Komarov el 14 de Ag. de 2012
a = '23';
str2num(a)
str2double(a)
  2 comentarios
Jordan
Jordan el 14 de Ag. de 2012
I tried your solution, but got the error
Error using str2num (line 33)
Requires string or character array input.
The variable is showing up as a < 1271x1 cell>. I'm sorry if I used the wrong wording in my question--I'm very new to all of this!
Oleg Komarov
Oleg Komarov el 14 de Ag. de 2012
a = {'23','33'; '12','1'};
cellfun(@str2num,a)
str2double(a)
Both approached work, I would go for str2double.

Iniciar sesión para comentar.


Azzi Abdelmalek
Azzi Abdelmalek el 14 de Ag. de 2012
Editada: Azzi Abdelmalek el 14 de Ag. de 2012
here an example:
A={'12' '45';'77' '15';'87' '524'} %your cell array
result=cellfun(@(x) str2num(x),A)

Categorías

Más información sobre Data Import from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by