Convert 8x3 char to string sequence (MATLAB)
    조회 수: 4 (최근 30일)
  
       이전 댓글 표시
    
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"
댓글 수: 0
채택된 답변
추가 답변 (2개)
  David Hill
      
      
 2022년 12월 1일
        val=['011'
    '010'
    '001'
    '000'
    '000'
    '001'
    '010'
    '011']
val=val'
val=val(:)'
댓글 수: 0
  Steven Lord
    
      
 2022년 12월 1일
        val = ...
    ['011'
    '010'
    '001'
    '000'
    '000'
    '001'
    '010'
    '011'];
s = join(string(val), '')
댓글 수: 2
  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), '')
  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))]
plot([t_string(2:end), t_cell(2:end)]);
legend({'string()', 'cellstr()'})
참고 항목
카테고리
				Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
