splitting cell array consists of string and numeric characters

I have a cell array (n x 1). Each cell looks something like this:
* 2021 3 29 0 0 0.00000000
I need to remove * from each cell and split the cell array into 6 columns consist of double values. For example;
2021 3 29 0 0 0
2021 3 30 0 0 0
.
.
.
How I can do that?

 採用された回答

Wan Ji
Wan Ji 2021 年 8 月 26 日
編集済み: Wan Ji 2021 年 8 月 26 日

1 投票

Use replace
S = {...}; % your n*1 cell array
S = arrayfun(@(i)replace(S{i},'*',''),1:1:numel(S),'uniform',false);

9 件のコメント

Wan Ji
Wan Ji 2021 年 8 月 26 日
編集済み: Wan Ji 2021 年 8 月 26 日
And if you want to transform S later to datetime then use'
DT = arrayfun(@(i)datetime(str2num(S{i})),(1:1:numel(S))')
sermet OGUTCU
sermet OGUTCU 2021 年 8 月 26 日
編集済み: sermet OGUTCU 2021 年 8 月 26 日
It removed the * and produced 1 x n cell array. But I need to split the "2021 3 29 0 0 0.00000000" into 6 columns. Could you show the next steps to do this?
Wan Ji
Wan Ji 2021 年 8 月 26 日
S = {...}; % your n*1 cell array
S = arrayfun(@(i)num2str(str2num(replace(S{i},'*',''))),1:1:numel(S),'uniform',false);
Wan Ji
Wan Ji 2021 年 8 月 26 日
Or you can do
S = {...}; % your n*1 cell array
S = arrayfun(@(i)replace(S{i},'* ',''),1:1:numel(S),'uniform',false);
sermet OGUTCU
sermet OGUTCU 2021 年 8 月 26 日
編集済み: sermet OGUTCU 2021 年 8 月 26 日
Dear @Wan, I still get 1 x n cell array instead of n x 6 double array consists of 2021 3 29 0 0 0.00000000 double values. I edited my question to be more specific.
Wan Ji
Wan Ji 2021 年 8 月 26 日
S = arrayfun(@(i)num2str(str2num(replace(S{i},'*',''))),1:1:numel(S),'uniform',false);
DT = arrayfun(@(i)datetime(str2num(S{i})),(1:1:numel(S))');
DV = datevec(DT);
YourCelln6 = mat2cell(DV,ones(size(DV,1),1),ones(size(DV,2),1));
Wan Ji
Wan Ji 2021 年 8 月 26 日
Wan Ji
Wan Ji 2021 年 8 月 26 日
You may see n*6 cell is not so good at all compared with DT or DV
sermet OGUTCU
sermet OGUTCU 2021 年 8 月 26 日
Thank you very much for the solution.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by