What do I have to add at the beginning of this loop?

前端 未结 2 1290
迷失自我
迷失自我 2021-01-27 20:35

how I can read the following files using the for loop: (can the loop ignore the characters in filenames?)

abc-1.TXT
cde-2.TXT
ser-3.TXT

2条回答
  •  一整个雨季
    2021-01-27 21:22

    First of all, why would you use strcat here? This is, by itself, a SINGLE string. All concatenation has already been done by the brackets [].

    ['MyFile\.......' num2str(i) '.TXT']
    

    Next, I'm not certain what is your question here. Is it how to load in the data? If the files are simply delimited numbers, with the same number of them on each line, then load will suffice to load them in, or perhaps you may need textread.

    My guess is you do not know how to build the main part of of the file name. You might do it this way:

    Names = {'abc' 'cde 'ser' 'wsz' 'aqz' 'iop'};
    for i = 1:6
      fn = ['MyFile',filesep,Names{i},'-',num2str(i),'.TXT'];
      data = load(fn);
    
      % do other stuff ...
    
    end
    

    If you don't want to create a variable with the names by typing them in, then use dir, perhaps like this to create a list of text file names:

    Names = dir('MyFile\*.TXT');
    

提交回复
热议问题