フィルターのクリア

Merging two arrays of two different types

4 ビュー (過去 30 日間)
khalida basheer
khalida basheer 2021 年 3 月 5 日
回答済み: Jorg Woehl 2021 年 3 月 6 日
How can I merge two arrays of two different typesI used the following code but lost the values of the array that contains numbers ????
a=[1 2 3]
a =
1 2 3
>> b=['aa'];
>> c=[a b]
c =###aa

採用された回答

Jorg Woehl
Jorg Woehl 2021 年 3 月 6 日
You are combining double values (from a) with character values (from b), which yields a character array according to MATLAB's class conversion rules. The doubles 1, 2, and 3 are converted to their Unicode character equivalents, which are control characters and only result in empty characters/whitespace when displayed.
If you want your resulting vector c to contain the numbers from a instead, first convert the doubles to characters using num2str. Using it on the array a will lead to additional whitespace, which you may or may not want... but you can strip that out using the replace function:
c = [num2str(a) b]
c =
'1 2 3aa'
c = replace([num2str(a) b], ' ', '')
c =
'123aa'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by