Unrecognized function or variable 'readlines'?

30 次查看(过去 30 天)
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.

更多回答(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