Unrecognized function or variable 'readlines'?

43 views (last 30 days)
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));

Accepted Answer

DGM
DGM on 17 Aug 2021
Edited: DGM on 17 Aug 2021
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.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!