hi suppose I have a char array C = [0001.hk 0002.hk]
and suppose I have a text file in my current directory called 0001.txt
I am wondering what are the code using the char array C(1) to open 0001.txt?
thx

2 commentaires

Kin
Kin le 3 Mar 2015
Suppose 0001.txt contains below
high low
101 103
102 104
Kin
Kin le 3 Mar 2015
Sorry 0001.txt should be below
high, low
101, 103
102, 104

Connectez-vous pour commenter.

 Réponse acceptée

Adam
Adam le 3 Mar 2015

0 votes

C = [0001.hk 0002.hk]
is not valid syntax. Do you mean you have a cell array with 2 cells? i.e.
C = {'0001.hk' '0002.hk'};
In which case:
C = strrep( C, 'hk', 'txt' )
would replace the '.hk' with '.txt', allowing you to loop round your cell array and open each file in turn, assuming that is what you want to do as e.g.
for i = 1:numel( C )
fid = fopen( C{i} );
% Do something with the file
end

Plus de réponses (0)

Catégories

Tags

Question posée :

Kin
le 3 Mar 2015

Commenté :

Kin
le 3 Mar 2015

Community Treasure Hunt

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

Start Hunting!

Translated by