# Converting a Cell of Cells into an Array of a String Column and Double Column

17 visualizaciones (últimos 30 días)
Pat el 31 de Mzo. de 2020
Respondida: Cris LaPierre el 31 de Mzo. de 2020
I have a 5x2 cell made up of cells. It is set up like this:
Red Car 50
Blue Car 45
Green Car 30
Black Car 60
Yellow Car 55
I need to convert the first column into strings, and the second column into a double. Is there anyway I can do this easily?
##### 2 comentariosMostrar NingunoOcultar Ninguno
matquest el 31 de Mzo. de 2020
Editada: matquest el 31 de Mzo. de 2020
I think we need a little more information. Are both columns currently strings? E.g.,
cell_array = {{'Red Car'},{'50'}; {'Blue Car'}, {'45'}};
Or is one column a string and the other a double? E.g.,
cell_array = {{'Red Car'},{50}; {'Blue Car'}, {45}};
Secondly, what is the end goal? Do you want two separate arrays? Or do you want a single array and to change the type in each column?
Pat el 31 de Mzo. de 2020
So right now it is stored as a cell of cells, where the first column is car types and the second column is speeds.
Both columns are currently stored as cells.
I need the first column to be a string and the second column to be a double.
The end goal is to plot a histogram of all speeds under a certain speed, and return a list with all of the associated strings.

Iniciar sesión para comentar.

### Respuestas (1)

Cris LaPierre el 31 de Mzo. de 2020
Arrays do not support mixed data types. Cells do, which is why your data is probably stored in a cell array. Something that does meet your objectives is a table. So if I had a 5x2 cell array carData
carData =
5×2 cell array
{'Red Car' } {[50]}
{'Blue Car' } {[45]}
{'Green Car' } {[30]}
{'Black Car' } {[60]}
{'Yellow Car'} {[55]}
I could use the function cell2table to make it a table where the first column (called a variable) is car type, and the second is car speed.
carTbl = cell2table(carData,'VariableNames',{'Car','Speed'})
carTbl =
5×2 table
Car Speed
______________ _____
{'Red Car' } 50
{'Blue Car' } 45
{'Green Car' } 30
{'Black Car' } 60
{'Yellow Car'} 55
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Tables en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by