Unrecognized function or variable 'readlines'?

조회 수: 30 (최근 30일)
Ryan
Ryan 2021년 8월 17일
댓글: Ryan 2021년 8월 17일
Hi, I am attempting to run the following code to read in the attached text file "data settings XRE.txt. However, even though the file is on my matlab path, I get the error message below. I am running Matlab 2020a.
[file,path] = uigetfile('*.txt');
if isequal(file,0)
disp('User selected Cancel');
else
disp(['User selected ', fullfile(path,file)]);
end
% file = uigetfile('*.txt')
txt = readlines(fullfile(path,file));
[field,value] = arrayfun(@customFunction,txt);
% data = struct;
% for n = 1:numel(field)
% data.(field(n)) = value(n);
% end
testStr='Ring level';
% Search for 1st occurence of 'testStr' in 'field'
k=find(field==testStr,1);
if not(isempty(k))
A = value(k);
disp([testStr,' =',num2str(value(k))])
end
testStr='x_end';
k=find(field==testStr,1);
if not(isempty(k))
B = value(k);
disp([testStr,' =',num2str(value(k))])
end
% data
function [f,v] = customFunction(str)
str = split(str,'=');
size(str);
f = strrep(deblank(str(1)),'"','');
if size(str,1) == 2
v = str2double(strrep(deblank(str(2)),'"',''));
else
v=NaN;
end
end
Unrecognized function or variable 'readlines'.
Error in Read_In_2 (line 21)
txt = readlines(fullfile(path,file));

채택된 답변

DGM
DGM 2021년 8월 17일
편집: DGM 2021년 8월 17일
It's not complaining about the txt file missing. It can't find readlines.m, because readlines() was introduced in R2020b. You just missed it ... or it missed you.
Finding an alternative really depends on what sort of stuff is in the file and how you're wanting to handle it.
  댓글 수: 1
Ryan
Ryan 2021년 8월 17일
Okay, great. Thank you for the additional information.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by