How to open file array with fopen?

조회 수: 9 (최근 30일)
Jacky
Jacky 2013년 7월 1일
Hi, I have a list of files that look like this:
J={'File1', 'File2', 'File3'}
It is not possible to open the file using fopen this way:
for i=1:length(J)
fid=fopen('J(1)', 'r')
%Some algorithms here...
fclose(fid)
end
Is there any possible way to use fopen by using looping? It seems like it only accepts the actual file name. Please help. Thanks!

채택된 답변

Jonathan Sullivan
Jonathan Sullivan 2013년 7월 1일
You just need to index into J properly. J looks to be a cell array so you need to use curly brackets.
Try replacing your fopen line with this
fid = fopen(J{i},'r');
  댓글 수: 1
Jacky
Jacky 2013년 7월 1일
It works. I thought I did that and it it didn't work. It must be something that I missed earlier on. Thank you so much for pointing that out for me.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 7월 1일

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by