将文件数据读入字符串元胞数组

Reading file data into cell array of character strings

我是 matlab 新手。我有文件 conatins 字符串列表,如:

ABCCD
HGAQ
VBSER

我需要把它读成cell array of character strings

我试过这段代码:

fid2 = fopen('C:\matlab\data\myfile.txt');
tline = fgetl(fid2);

while ischar(tline)
    disp(tline)
    tline = fgetl(fid2);
end

fclose(fid2);

但是,我不知道如何将输出转换为字符串元胞数组

importdata 为您完成:

>> x = importdata('file.txt');
x = 
    'ABCCD'
    'HGAQ'
    'VBSER'

>> whos x
  Name      Size            Bytes  Class    Attributes
  x         3x1               364  cell