필터 지우기
필터 지우기

How can I input every file in a directory ending with .txt into my Matlab program while logged in through ssh?

조회 수: 2 (최근 30일)
I have a script/program that compares two inputs. I'd like the first input to stay the same throughout. For the other input, I want it to take in every single file ending with .txt in a directory, and execute the program.
How can I do so?
I'm working through ssh, so I'm not sure if that changes anything.
Also, would this code to run through all the files be placed in the command window or in my script?

채택된 답변

per isakson
per isakson 2015년 11월 14일
편집: per isakson 2015년 11월 14일
"every single file ending with .txt in a directory," &nbsp
Try
sad = permute( dir( fullfile( folderspec, '*.txt' ) ), [2,1] );
for s = sad
fullfile( folderspec, s.name )
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 14일
As your script takes two inputs, you should convert it to a function. Then create either a function (preferred) or script that calls upon it, using the techniques shown in
  댓글 수: 2
Thorsten
Thorsten 2015년 11월 14일
That's fine. This is covered in the second part of the above reference:
"The second method is if you want to process all the files whose name matches a pattern in a directory. You can use the DIR function to return a list of all file names matching the pattern, for example all .txt files or all .csv files, or all files named myFilennnn.dat (where nnnn is some number)."

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by