필터 지우기
필터 지우기

how to convert a cell array to a string array

조회 수: 244 (최근 30일)
梓昂 郑
梓昂 郑 2022년 1월 10일
댓글: Walter Roberson 2023년 5월 13일
I have a cell array of 2048*1,each cell countains a string element, and i want to convert it into a string array (so that i could make it one hot coded)
how cloud i slove it?
  댓글 수: 2
Stephen23
Stephen23 2022년 1월 10일
편집: Stephen23 2022년 1월 10일
"I have a cell array of 2048*1,each cell countains a string element..."
Highly unusual and not recommended: "Avoid using cell arrays of strings. When you use cell arrays, you give up the performance advantages that come from using string arrays."
The best solution is to avoid creating this cell array in the first place, and instead store the data in a string array (or as a cell array of character vectors) right from the start. How was this cell array created?
Kelvin Prosyk
Kelvin Prosyk 2023년 5월 13일
The OP is valid. There could be situations where it is unavoidable. For example, reading in mixed data from an Excel spreadsheet using the readcell function.

댓글을 달려면 로그인하십시오.

답변 (1개)

Yusuf Suer Erdem
Yusuf Suer Erdem 2022년 1월 10일
S = {'Hello',' ','world',' ','i',' ','am',' ','here'}
ss = [S{:}]
  댓글 수: 4
Kelvin Prosyk
Kelvin Prosyk 2023년 5월 13일
편집: Kelvin Prosyk 2023년 5월 13일
Any valid answer to this question? OP wanted to convert to an array of strings, not a single vector of char. I have a similar problem.
Walter Roberson
Walter Roberson 2023년 5월 13일
S = {"Hello"," ","world"," ","i"," ","am"," ","here"}.'
S = 9×1 cell array
{["Hello"]} {[" " ]} {["world"]} {[" " ]} {["i" ]} {[" " ]} {["am" ]} {[" " ]} {["here" ]}
SA = reshape([S{:}], size(S))
SA = 9×1 string array
"Hello" " " "world" " " "i" " " "am" " " "here"

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by