Combine string elements and number elements in one matrix or cell array.
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2018-8-21
Have a read here (or here for more general advice) and here. It will greatly improve your chances of getting an answer.
回答(1 个)
Adam Danz
2018-8-21
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!