Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Annas Farooq
Annas Farooq 2019 年 2 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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