Convert 8x3 char to string sequence (MATLAB)

2 ビュー (過去 30 日間)
high speed
high speed 2022 年 12 月 1 日
コメント済み: Walter Roberson 2022 年 12 月 1 日
Dear,
I have this char characters on MATLAB:
val =
'011'
'010'
'001'
'000'
'000'
'001'
'010'
'011'
I want to convert them to one sequence of type string to obtain this result:
"011010001000000001010011"

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 1 日
reshape(val.', 1, [])

その他の回答 (2 件)

David Hill
David Hill 2022 年 12 月 1 日
val=['011'
'010'
'001'
'000'
'000'
'001'
'010'
'011']
val = 8×3 char array
'011' '010' '001' '000' '000' '001' '010' '011'
val=val'
val = 3×8 char array
'00000000' '11000011' '10100101'
val=val(:)'
val = '011010001000000001010011'

Steven Lord
Steven Lord 2022 年 12 月 1 日
val = ...
['011'
'010'
'001'
'000'
'000'
'001'
'010'
'011'];
s = join(string(val), '')
s = "011010001000000001010011"
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 12 月 1 日
Without using string(), such as for older MATLAB:
val = ...
['011'
'010'
'001'
'000'
'000'
'001'
'010'
'011'];
s = strjoin(cellstr(val), '')
s = '011010001000000001010011'
Walter Roberson
Walter Roberson 2022 年 12 月 1 日
Interesting, using string() is measurably faster here.
format long g
val = char(randi(+'0', +'1'), 5000, 50);
N = 100;
t_string = zeros(N,1);
t_cell = zeros(N,1);
for K = 1 : N; start = tic; s = join(string(val), ''); stop = toc(start); t_string(K) = stop; end
for K = 1 : N; start = tic; s = strjoin(cellstr(val), ''); stop = toc(start); t_cell(K) = stop; end
[mean(t_string(2:end)), mean(t_cell(2:end))]
ans = 1×2
1.0e+00 * 1.15959595959596e-05 4.07575757575758e-05
plot([t_string(2:end), t_cell(2:end)]);
legend({'string()', 'cellstr()'})

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by