How to use shell commands including variables from matlab?

조회 수: 8 (최근 30일)
Pal Szabo
Pal Szabo . 2017년 9월 20일
댓글: Pal Szabo . 2017년 9월 20일
I have N files, file1 file2 file3, ... fileN. I know that
!rm file1
removes file1. How can I create a loop, which removes file1 file2 file3 ... fileN? My idea: create array, myfiles = ("myfile1","myfile2","myfile3") Than call:
for i=1:N
!rm myfiles(i)
This doesn't work however, matlab tries to remove file "myfiles(i)", not myfile1, myfile2,... myfileN.
How to solve this problem?

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 20일
for filecell = myfiles
filename = filecell{1};
delete(filename) ;
If deletion was just a sample operation
for filecell = myfiles
filename = filecell{1};
cmd = sprintf('rm "%s"', filename );

추가 답변 (0개)


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

Community Treasure Hunt

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

Start Hunting!

Translated by