Open files from documents in loop

조회 수: 1 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 10월 21일
댓글: Chunru 2021년 10월 21일
I want to open several files in a for loop.
Anyone who can help me with this?
For now I tried this:
a = "/Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-"
b = r
c = ".csv"
filename = strcat(a,b,c);
filename = convertCharsToStrings(filename);
truck1 = readtable(filename, opts);
How can I make r the variable (1 to 20)?
  댓글 수: 1
Chunru
Chunru 2021년 10월 21일
a = "/Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-";
c = ".csv";
for r=1:20
filename = sprintf('%s%d%s', a, r, c);
disp(filename)
%truck1 = readtable(filename, opts);
end
/Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-1.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-2.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-3.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-4.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-5.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-6.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-7.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-8.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-9.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-10.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-11.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-12.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-13.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-14.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-15.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-16.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-17.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-18.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-19.csv /Users/diontheunissen/Documents/Smart_Driver/RawData/Scania/e-20.csv

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by