Filter löschen
Filter löschen

How to open file array with fopen?

10 Ansichten (letzte 30 Tage)
Jacky am 1 Jul. 2013
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...
Is there any possible way to use fopen by using looping? It seems like it only accepts the actual file name. Please help. Thanks!

Akzeptierte Antwort

Jonathan Sullivan
Jonathan Sullivan am 1 Jul. 2013
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 Kommentar
Jacky am 1 Jul. 2013
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 1 Jul. 2013


Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by