フィルターのクリア

How can I merge text to numeric data?

2 ビュー (過去 30 日間)
Benjamin Horsley
Benjamin Horsley 2021 年 2 月 13 日
コメント済み: Benjamin Horsley 2021 年 2 月 13 日
I have two variables:
A = [1 2 3 4 5 6 7 8 9 10]';
B = ["L", "R"]';
How can I merge A and B where B is of the same height (number of rows) as A? In other words, I want to have a second colum of alternating "L" and "R" .
Appreciate any help. Thanks.

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 13 日
編集済み: KALYAN ACHARJYA 2021 年 2 月 13 日
A = [1 2 3 4 5 6 7 8 9 10]';
B = ["L", "R"]';
r=length(A)/length(B);
B_update=repmat(B,[r,1])
t=table(A,B_update)
Result:
t =
10×2 table
A B_update
__ ________
1 "L"
2 "R"
3 "L"
4 "R"
5 "L"
6 "R"
7 "L"
8 "R"
9 "L"
10 "R"
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 13 日
Note that it is not possible to have a numeric array that combines numbers and text, which is why the above solution puts the data into a table.
Benjamin Horsley
Benjamin Horsley 2021 年 2 月 13 日
Thank you, guys! Really appreciate the help and explanation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by