【问题标题】:Reading file data into cell array of character strings将文件数据读入字符串元胞数组
【发布时间】:2015-06-04 15:47:51
【问题描述】:

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

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);

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

【问题讨论】:

    标签: arrays string matlab file-io cell-array


    【解决方案1】:

    importdata 为你做这件事:

    >> x = importdata('file.txt');
    x = 
        'ABCCD'
        'HGAQ'
        'VBSER'
    
    >> whos x
      Name      Size            Bytes  Class    Attributes
      x         3x1               364  cell    
    

    【讨论】:

      猜你喜欢
      • 2011-02-07
      • 2015-03-15
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多