how to process multiple file in matlab

24 views (last 30 days)
i an a beginner in mat lab,i want to open a spice simulator using mat lab provide a file to it using mat lab and the output generated will be in .DAT so i want mat lab to open this DAT file and do the various function to plot the graph.

Answers (2)

Image Analyst
Image Analyst on 5 Apr 2014
myFolder = 'C:\Documents and Settings\yourUserName\My Documents';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.dat');
dataFiles = dir(filePattern);
for k = 1:length(dataFiles)
baseFileName = dataFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
t = readtable(fullFileName);
end
  12 Comments
Walter Roberson
Walter Roberson on 17 Sep 2022
No, Image Analyst does not accept direct contacts.

Sign in to comment.


Thiago de Aquino Costa Sousa
You were completely correct. For some reason, the system I use to collect the data didn't name my second-to-last column, and pulled the last column's name into place, leaving the last column unnamed. See the pictures:
Correct
Mislabelled
Do you have any idea on how could I fix this problem with a code, because I have many files to solve the same problem. Thanks a lot for your time.
  8 Comments
Thiago de Aquino Costa Sousa
So now, what I have is a masterTable, with all lines (total 271,928) and columns (total 85) of all my files. However, it doesn't show me anywhere to which ever participant this data come from, because I don't have a column with the subject id. This information can be obtained from the first structure of subfolders, remember this picture.
From now and so on, I will need to perform some maths and plots for each participant. Then, I would like to ask you your opinion on what could be a better approach, to create a new column Subject.Id and fill it with the subject identification for all the lines belonging to each participant (I guess I could create something like masterTable.Subject_Id = ?, but I don't know how to do it in the loop, for each participant). Or if could do it in another way, calling the subfolder for each participant, and then applying the next code. Please guys, I would really appreciate this another help.
Thiago de Aquino Costa Sousa
I added this line of code:
thisTable.Subject_Id = fullfilename(98:102);
That returns the Id of the subject, but when I run it I got the following error:
Error using . To assign to or create a variable in a table, the number of rows must match the height of the table.
Error in Extracting_data_and_making_mastertable (line 14)
thisTable.Subject_Id = fullfilename(98:102);
Any cues how can I correct it?

Sign in to comment.

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!