MATLAB Answers

Cicle for read data.

조회 수: 2(최근 30일)
Jair Bocanegra Flores
Jair Bocanegra Flores 2021년 7월 1일
댓글: Jair Bocanegra Flores 2021년 7월 2일
Hi. I'm trying to read a group of .dat files using the next code and I'm getting the error "Array indices must be positive integers or logical values."
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 3);
% Specify range and delimiter
opts.DataLines = [18, 1138];
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["LagTime", "g^-2","vacio"];
opts.SelectedVariableNames = ["LagTime", "g^-2"];
opts.VariableTypes = ["double", "double", "string"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "vacio", "WhitespaceRule", "preserve");
opts = setvaropts(opts, "vacio", "EmptyFieldRule", "auto");
% Import the data
for k=0:95
T= sprintf("M3%d.dat",k);
M3{k}= readtable(T, opts);
end

채택된 답변

David Hill
David Hill 2021년 7월 1일
for k=0:95
T= sprintf("M3%d.dat",k);
M3{k+1}= readtable(T, opts);%must start indexing at 1
end
  댓글 수: 1
Jair Bocanegra Flores
Jair Bocanegra Flores 2021년 7월 2일
Thank you!!

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

추가 답변(0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by