MATLAB Answers


Textscan Usage. One character in one cell.

Asked by Priya
on 15 Apr 2013

I have a text file in which following characters are written


I want to store it in a cell array of order 1 X 5 , with each character in one cell.

I tried using Textscan as follows, but it gives only 1X1 cell with all characters in one cell.

Kindly Help.




No products are associated with this question.

1 Answer

Answer by Friedrich
on 15 Apr 2013
Edited by Friedrich
on 15 Apr 2013
 Accepted answer


>> fid = fopen('in.txt')
>> data = textscan(fid,'%c')

data =

    [5x1 char]
>> fclose(fid)

data is a 1x1 Cell which contains a 1x5 Char Array. And in the case you really need a cell you can use mat2cell:

new_data = mat2cell(data{1},ones(numel(data{1}),1),1)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!