I'm trying to merge two columns in a table. I tried this:
L = readtable( fileLog );
L2 = mergevars(L,["Var2","Var3"]);
But this end up with Var2 as a cell array.
L2 =
6×2 table
Var1 Var2
_________ _______________________
1.679e+09 {'Start'} {'ping' }
1.679e+09 {'Start'} {'copy' }
1.679e+09 {'Stop' } {'copy' }
1.679e+09 {'Start'} {'delete'}
1.679e+09 {'Stop' } {'delete'}
1.679e+09 {'Stop' } {'ping' }
How can I combine each row of Var 2 to be strings like "Start ping"? I tried using strjoin, but that gives me a single string.

 採用された回答

Cris LaPierre
Cris LaPierre 2023 年 3 月 16 日
編集済み: Cris LaPierre 2023 年 3 月 16 日

0 投票

I would do this.
fileLog = "logData.csv";
L = readtable( fileLog, "TextType","string")
L = 6×3 table
Var1 Var2 Var3 ________ _______ ________ 1.68e+09 "Start" "ping" 1.68e+09 "Start" "copy" 1.68e+09 "Stop" "copy" 1.68e+09 "Start" "delete" 1.68e+09 "Stop" "delete" 1.68e+09 "Stop" "ping"
L2 = L(:,"Var1");
L2.Var2 = L.Var2 + " " + L.Var3
L2 = 6×2 table
Var1 Var2 ________ ______________ 1.68e+09 "Start ping" 1.68e+09 "Start copy" 1.68e+09 "Stop copy" 1.68e+09 "Start delete" 1.68e+09 "Stop delete" 1.68e+09 "Stop ping"

1 件のコメント

dormant
dormant 2023 年 3 月 21 日
Many thanks

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

その他の回答 (1 件)

Voss
Voss 2023 年 3 月 16 日

0 投票

L = readtable( fileLog );
L2 = convertvars(mergevars(L,["Var2","Var3"]),"Var2",@(a)join(a," "));

1 件のコメント

dormant
dormant 2023 年 3 月 21 日
Many thanks

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

カテゴリ

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

製品

リリース

R2022b

タグ

質問済み:

2023 年 3 月 16 日

コメント済み:

2023 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by