フィルターのクリア

How to split table cell into two columns based on data type?

2 ビュー (過去 30 日間)
Jessica Jiaying
Jessica Jiaying 2021 年 8 月 7 日
コメント済み: Jessica Jiaying 2021 年 8 月 9 日
I have imported my data using readtable so that it is currently like this:
I would like to further split the data in the two selected columns (Res1 and Res2) so that each row looks like this:
(Taking the first row as an example and each tab delimiting each column)
7.8610 8.3600 659 1318 H Y 23 H H 20
where "Y23" and "H20" are now split into "Y", "23", "H", "20" respectively in separate columns.
I will greatly appreciate any advice, thank you!
  1 件のコメント
Jessica Jiaying
Jessica Jiaying 2021 年 8 月 7 日
To add on, the values for "Res1" and "Res2" are all a character followed by numbers (can be 1 or 2) with no spacing in between as this is an output derived from a program.

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

採用された回答

Yazan
Yazan 2021 年 8 月 8 日
編集済み: Yazan 2021 年 8 月 8 日
Below is an example with toy data showing what you need to do.
clc, clear,
T1 = [1;2]; T2 = {'Y12'; 'Y2'}; T3 = {'H12'; 'H0'};
T = table(T1, T2, T3);
% get letters and digits of column 2
T2Str = erase(T.T2, digitsPattern);
T2Dig = erase(T.T2, lettersPattern);
% get letters and digits of column 3
T3Str = erase(T.T3, digitsPattern);
T3Dig = erase(T.T3, lettersPattern);
% new table
Tnew = table(T1, T2Str, T2Dig, T3Str, T3Dig);
disp(T)
T1 T2 T3 __ _______ _______ 1 {'Y12'} {'H12'} 2 {'Y2' } {'H0' }
disp(Tnew)
T1 T2Str T2Dig T3Str T3Dig __ _____ ______ _____ ______ 1 {'Y'} {'12'} {'H'} {'12'} 2 {'Y'} {'2' } {'H'} {'0' }
  1 件のコメント
Jessica Jiaying
Jessica Jiaying 2021 年 8 月 9 日
Thank you so much Yazan! Your example code allowed me to understand how to apply to my data perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by