how to process multiple file in matlab

9 ビュー (過去 30 日間)
Siddharth Pande
Siddharth Pande 2014 年 4 月 5 日
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.

回答 (2 件)

Image Analyst
Image Analyst 2014 年 4 月 5 日
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 件のコメント
Thiago de Aquino Costa Sousa
Thiago de Aquino Costa Sousa 2022 年 9 月 17 日
Is there anyway I could contact you directly @Image Analyst?
Walter Roberson
Walter Roberson 2022 年 9 月 17 日
No, Image Analyst does not accept direct contacts.

サインインしてコメントする。


Thiago de Aquino Costa Sousa
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
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 件のコメント
Thiago de Aquino Costa Sousa
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.
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
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 ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by