how to process multiple file in matlab
18 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Image Analyst
2014-4-5
See the FAQ for code examples: http://matlab.wikia.com/wiki/FAQ?title=FAQ&cb=9092#How_can_I_process_a_sequence_of_files.3F like:
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
Thiago de Aquino Costa Sousa
2022-9-17
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1128280/image.png)
Mislabelled
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1128285/image.png)
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 个评论
Thiago de Aquino Costa Sousa
2022-9-18
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1128535/image.jpeg)
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
2022-9-18
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?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!