필터 지우기
필터 지우기

Handling character array rather than cell

조회 수: 2 (최근 30일)
Yongmin
Yongmin 2015년 6월 13일
댓글: Yongmin 2015년 6월 13일
Hello,
I have a text file (file name: X) having identifiers with 64 byte characters. I used textscan function to read the identifiers in MATLAB as follows:
fid = fopen('X','r');
data = textscan(fid,'%64c','delimiter',',');
As a results, I have a cell of records having 64 byte identifiers. My question is how to have a character array instead of a cell?
I can use function char() to change a cell into a character array:
data = char(data);
But I want to generate a character array when I read the text file using textscan because char() function requires another long time to execute.
Thank you for your attention.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 6월 13일
  댓글 수: 1
Yongmin
Yongmin 2015년 6월 13일
편집: Yongmin 2015년 6월 13일
Hello Azzi,
Do you mean use data{:} instead of using char() ? I will try to use the command.
Thanks a lot for your answer!!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 13일
fid = fopen('X','r');
data = textscan(fid,'%64c','delimiter',',');
data = data{1}; %extracts array of char from cell array
When you use %c format in textscan the corresponding output is an array of character; and as usual, the outputs are all encapsulated in a cell array.
This differs from using %s format in textscan, in which case the corresponding output is a cell array of strings, which is something you might want to apply char() to in order to create a character array.
There is no way to get textscan to return values not encapsulated in a cell array. There is, however, no conversion time to use data{1} to get at the character array.
  댓글 수: 1
Yongmin
Yongmin 2015년 6월 13일
Dear Walter Robserson,
Thanks a lot for your kind explanation. I understand the limitation of textscan function.

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

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by