0

I have multiple text files like Symbol1010, Symbol1020...SymbolXXXX.

I want to know if there is any easiest way to process those files in to mat files.

Specifications:

  1. All the files have the same header (strings) in the first row.
  2. All the files have the date in their first column
  3. All the files have the same number of rows and columns.

I tried using importdata and it works good for single file.

3 Answers 3

1

If "importdata" works well for your files I would strongly suggest using it in a loop. If you encounter problems while implementing that, please be more specific in your question. Below is a sample that might be a good starting point.

prefix = 'Symbol';
suffixes = (1010:10:1100);
for idx = 1 : length(suffixes)
    filename = [prefix, num2str(suffixes(idx))];
    A = importdata(filename);
    save(filename,'A');
end
Sign up to request clarification or add additional context in comments.

Comments

0

Your question is missing quite a lot of detail so I can only give you a general answer, but I'm going to assume that you already know that you should put the single-file code in a loop and that in your single-file example you currently hardcode the name of the file.

Your first problem would then be how to get the list of files. The functions you want are dir and possibly fullfile, you should check out the documentation by typing doc dir in the console. Matlab has extensive documentation and you can often find answers in there very quickly indeed.

If you need more specific answers you would need to post the code that you have so far, a description of what you want to happen and what is happening. I recommend the stackoverflow.com/tour as a good introduction to how to pose a good question.

Comments

0

Thanks michael and xenoclast for the help. I got this

d = dir('*.txt');
nfiles = length(d);

%Conversion of data in text format to Mat format
data = cell(1, nfiles);

for k = 1:nfiles
    data{k} = importdata(d(k).name);
end

1 Comment

Hi Gopi, you should mark the answer which helped you most as the best answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.