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

조회 수: 16 (최근 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

답변 (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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by