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

6 ビュー (過去 30 日間)
Kiril Milev
Kiril Milev 2018 年 8 月 21 日
回答済み: Adam Danz 2018 年 8 月 21 日
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
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.
Kiril Milev
Kiril Milev 2018 年 8 月 21 日
Thank you!

サインインしてコメントする。

回答 (1 件)

Adam Danz
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.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by