How to use strsplit in cell arrays

I have a cell array (named B) with the following dimensions (120 x 1) filled with what I believe are strings. Following is an example of the first 2 cells of the array.
Message_2 = hex2dec('2');
Message_4A = hex2dec('4A');
and so on....
I would like to create a new array (120 x 1) that would output:
2
4A
so on...
I am able to take the contents of one cell, convert into a character and then use the strsplit by delimiter to get what I need. But I am not able to do this for the whole cell array. when I use the cellfun with the char function or the strsplit, I am getting errors.

 採用された回答

Stephen23
Stephen23 2018 年 9 月 9 日
編集済み: Stephen23 2018 年 9 月 9 日

0 投票

>> B = {'Message_2 = hex2dec(''2'');','Message_4A = hex2dec(''4A'');'};
>> regexp(B,'(?<=\()[^)]+','once','match')
ans =
'2'
'4A'

2 件のコメント

Alli Rat
Alli Rat 2018 年 9 月 9 日
Hi Stephen, thanks for your answer. Say my cell array is called "B" with dimensions (120 x 1). Is there a way to avoid writing individual strings in the code and just use the name of the array (B)?. Thanks!
Stephen23
Stephen23 2018 年 9 月 9 日
編集済み: Stephen23 2018 年 9 月 9 日
@alekhya ratnala: I only wrote that cell array B as an example, so that my code has something to work with. Of course you should use your B cell array: the first argument to regexp is your cell array, whatever it might be called.

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

その他の回答 (0 件)

カテゴリ

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

製品

質問済み:

2018 年 9 月 9 日

編集済み:

2018 年 9 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by