【问题标题】:Matlab .txt file read using space delimiter使用空格分隔符读取 Matlab .txt 文件
【发布时间】:2014-10-17 02:27:44
【问题描述】:

我想使用空格分隔符将文本文件读入矩阵。我的文本文件包含如下信息:

AJ_Lamas/AJ_Lamas_0001.jpg 58 68 134 134 -2 10 31 43 53 45 Aaron_Eckhart/Aaron_Eckhart_0001.jpg 63 72 126 126 0 10 34 35 53 Aaron_Guiel/Aaron_Guiel_0001.jpg 54 67 144 144 -1 10 34 44 58 Aaron_Patterson/Aaron_Patterson_0001.jpg 47 62 148 148 1 10 44 65 63 Aaron_Peirsol/Aaron_Peirsol_0001.jpg 64 72 127 127 0 10 33 43

我试过了:

m=dlmread('D:\MatlabCode\lfw_ffd_ann.txt', ' ')

但它显示了一些错误:

使用 dlmread 时出错(第 139 行) 文件和格式字符串不匹配。 无法从文件中读取数字(第 1u 行,第 1u 字段)==> image_name face_bbox_x face_bbox_y face_bbox_width face_bbox_height headpose num_facial_features left_eye_left_x left_eye_left_y left_eye_right_x left_eye_right_y 口_left_x 口_left_y 口_right

【问题讨论】:

  • 看来你可能有一个标题行,你也应该想想你是如何处理的。

标签: matlab


【解决方案1】:

你不能真正阅读它,它不是一个矩阵,而是一个单元格,并且可以使用textscan() 实现它。假设你想读取实际的字符串(我假设是因为文件名),它会是这样的:

 fid=fopen('D:\MatlabCode\lfw_ffd_ann.txt');
 C=textscan(fid,'%s','delimiter',' ');
 fclose(fid);

希望对你有帮助

【讨论】:

  • 通常,当一个答案可以帮助您解决问题时,您会将其标记为已接受或投票;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多