Info

此问题已关闭。 请重新打开它进行编辑或回答。

Trying to use dlmread and getting a couple errors, pretty urgent

1 次查看(过去 30 天)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 47, field number 4) ==> + 0.64967 1.00000 1.54 1 1 1 1 1.54\n
I literally just installed a free trial and started using MATLAB. I'm trying to use some data I got from the Human Mortality Database (uploaded a text file). I attached the data to this thread. I'm trying to convert this data into a matrix.
Any ideas? Also, if anyone's willing to get in touch with me and guide me through this entire process of using MATLAB for my project, I'll even go as far as giving you a gift on PayPal.

回答(1 个)

Image Analyst
Image Analyst 2019-2-22
编辑:Image Analyst 2019-2-22
I think you're going to have to write a custom reader, because not all lines have the same number of numbers on them. Some lines have "110+ " instead of two numbers.
Use
% Open the file.
fileID = fopen(fullFileName, 'rt');
% Read the first line of the file.
textLine = fgetl(fileID);
while ischar(textLine)
% Print out what line we're operating on.
fprintf('%s\n', textLine);
% Read the next line.
textLine = fgetl(fileID);
% Now parse textLine and be sure to handle all special/unusual cases.
if contains(textLine, '110+')
% etc.
else
end
end
% All done reading all lines, so close the file.
fclose(fileID);
  1 个评论
Annas Farooq
Annas Farooq 2019-2-22
Alright- just did that, here are two resulting errors:
Error using contains
Search term must be a string array, character vector, or cell array of character vectors.
Error in untitled2 (line 11)
if contains(textLine, '110+')

Community Treasure Hunt

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

Start Hunting!

Translated by