transform the cell 'string' containing strings into a single string

조회 수: 3 (최근 30일)
Alberto Acri
Alberto Acri 2023년 9월 6일
답변: Paul 2023년 9월 6일
Hi! I need to transform the cell 'string' containing strings into a single string, like this:
string_new = "54 55 56 57 59 60 61 62 63 69 ";

채택된 답변

Voss
Voss 2023년 9월 6일
One way:
load string.mat
S = string; % I rename your variable "string" and clear it
clear string % because I'm going to use the string() function
string_new = append(join(string(S)," ")," ")
string_new = "54 55 56 57 59 60 61 62 63 69 "

추가 답변 (1개)

Paul
Paul 2023년 9월 6일
load string.mat
who
Your variables are: ans cmdout string
string
string = 1×10 cell array
{["54"]} {["55"]} {["56"]} {["57"]} {["59"]} {["60"]} {["61"]} {["62"]} {["63"]} {["69"]}
string_new = join(horzcat(string{:}))
string_new = "54 55 56 57 59 60 61 62 63 69"
Probably not a good idea to have a variable named string, which is conflicting with string

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by