Unrecognized function or variable 'readlines'?
27 ビュー (過去 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));
0 件のコメント
採用された回答
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!