Cell array/Character array to string

4 ビュー (過去 30 日間)
Jonathan Midgley
Jonathan Midgley 2012 年 4 月 18 日
I have generated a cell array of characters eg. cea={'8' '_1' '9' '_3'}. I need this to be converted to a string '8_19_3' for labelling a figure.
I have converted to a character array using cha=char(cea), in this example it will be a 4x2 array. Then the correct string can be given by str=[cha(1,:),cha(2,:),cha(3,:),cha(4,:)] (except this has unwanted spaces).
However the length of the character array can vary in a loop. Using str=[cha(1:length(cha),:)] does not give the same string as I think it should.
Why is this and is there a better way to go about doing it?
Thanks

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 4 月 18 日
cea={'8' '_1' '9' '_3'}
str = strcat(cea{:})
or
str = [cea{:}];
  1 件のコメント
Jonathan Midgley
Jonathan Midgley 2012 年 4 月 18 日
Simple, perfect

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by