Unrecognized function or variable 'readlines'?

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

 Akzeptierte Antwort

DGM
DGM am 17 Aug. 2021
Bearbeitet: DGM am 17 Aug. 2021

1 Stimme

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 Kommentar

Ryan
Ryan am 17 Aug. 2021
Okay, great. Thank you for the additional information.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2020a

Tags

Gefragt:

am 17 Aug. 2021

Kommentiert:

am 17 Aug. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by