Convert cell array with characters to vector with numbers?
古いコメントを表示
Hi guys,
I've been trying to get a cell array that looks like this:
y =
'a'
'a'
'a'
'b'
'b'
'a'
'a'
'b'
'a'
'b'
'b'
'b'
to convert it to a vector that looks like this: y =
1
1
1
0
0
1
1
0
1
0
0
0
How do I do this? I've been trying to get it right with strfind and using it on the cell array and use those results to alter the contents of the cell array before I convert it to a vector with cell2mat().
But no luck so far.
Can someone help me with this?
Thanks in advance.
採用された回答
その他の回答 (2 件)
the cyclist
2012 年 6 月 17 日
One of many ways:
strcmp(y,'a')
1 件のコメント
Jan
2012 年 6 月 18 日
I prefer this, because it is lean and fast for small and large input.
Andrei Bobrov
2012 年 6 月 17 日
50 - (char(y)-'0')
1 件のコメント
Walter Roberson
2012 年 6 月 17 日
'b' - char(y)
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!