How can i remove string entries from Cell array?

I have a cell array containing strings like that eg A={['aaa' 'char(9)' 'aaaa']} how can i keep only the first string?

4 件のコメント

James Tursa
James Tursa 2016 年 4 月 6 日
編集済み: James Tursa 2016 年 4 月 6 日
Do you mean you are starting with a cell array that has many elements, and that each element has strings that have "unprintable" characters in them, and you want to truncate each string up to this character? Or do you actually have the characters 'char(9)' as part of the string and you want to truncate up to that point? Or ...?
achilleas flo
achilleas flo 2016 年 4 月 6 日
Just to be more specific : I have a cell array of 300000x1 cell containing string elements. its cell is like that :
{['"I am an engineer" ' char(9) '' char(9) '' char(9) '' char(9) '' char(9) 'Hello']}
i just want to keep : I am an engineer.
***** JUST to mention i dont know if helps when i use display(A(10)); i get something like that :
'"I am an engineer" Hello'
******
Aleksey Trubitsyn
Aleksey Trubitsyn 2016 年 4 月 6 日
A actually only has cell because of the inner []. That cell is the string 'aaachar(9)aaaa'. You can use cellfun to do a string operation on that cell. if A were {'aaa','char(9)','aaaa'} then you could do B = A(2:end)
achilleas flo
achilleas flo 2016 年 4 月 7 日
Probably i need a regular expression to do the job, but how.....any help will be great

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

回答 (1 件)

Eugene
Eugene 2016 年 4 月 6 日

0 投票

I think I understand what you meant. For example
>> A = {'aaaa' char(9) 'aaaaa'}
A =
'aaaa' ' ' 'aaaaa'
>> A(2:3) = [];
>> A
A =
'aaaa'
>> class(A)
ans =
cell
>> size(A)
ans =
1 1
Or to simply keep the first cell array element.
A = {A{1}}

1 件のコメント

achilleas flo
achilleas flo 2016 年 4 月 6 日
Thanks for the reply but although The command syntax, of your suggestion is accepted from matlab. I do not have the expected results. Just to be more specific : I have a cell array of 300000x1 cell containing string elements. its cell is like that :
{['"I am an engineer" ' char(9) '' char(9) '' char(9) '' char(9) '' char(9) 'Hello']}
i just want to keep : I am an engineer.
***** JUST to mention i dont know if helps when i use display(A(10)); i get something like that :
'"I am an engineer" Hello'
******

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

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

質問済み:

2016 年 4 月 5 日

コメント済み:

2016 年 4 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by