Combine string elements and number elements in one matrix or cell array.

Hello guys,
How can I combine string and number elements in one matrix or cell array and how can I manipulate the data after that? Thanks :)
Kiril

2 comentarios

Have a read here (or here for more general advice) and here. It will greatly improve your chances of getting an answer.

Iniciar sesión para comentar.

Respuestas (1)

As Rik pointed out, your request is vague, but maybe this will get you started.
You must use a cell array to combine numbers and strings in the same variable.
Here's an example
bg = { 3 5 9; 'Sofia', 'Plovdiv', 'Burgas'}'
bg =
3×2 cell array
{[3]} {'Sofia' }
{[5]} {'Plovdiv'}
{[9]} {'Burgas' }
There's lots of ways to interact with this cell array (ie, 'manipulate the data').
Take the mean of column 1
mean([bg{:}])
Find the value in column 1 associated with whatever row contains 'Burgas' in column 2
bg{strcmp(bg(:,2), 'Burgas'), 1}
Get the data in the 2nd row, 1st column
bg(2,1) %the result is another cell (1 element)
bg{2,1} %the result is a matrix (1 element)
If there's something more specific you'd like to know, describe it in the comment section.

Categorías

Etiquetas

Preguntada:

el 21 de Ag. de 2018

Respondida:

el 21 de Ag. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by