Opening a sequence of text file

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 Comments

Suppose 0001.txt contains below
high low
101 103
102 104
Sorry 0001.txt should be below
high, low
101, 103
102, 104

Sign in to comment.

 Accepted Answer

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

More Answers (0)

Categories

Tags

Asked:

Kin
on 3 Mar 2015

Commented:

Kin
on 3 Mar 2015

Community Treasure Hunt

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

Start Hunting!