MATLAB: Opening a sequence of text file

text files

hi suppose I have a char array C = []
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?

Best Answer

  • C = []
    is not valid syntax. Do you mean you have a cell array with 2 cells? i.e.
    C = {'' ''};
    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