필터 지우기
필터 지우기

how to process multiple file in matlab

조회 수: 25 (최근 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 CenterFile 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!

Translated by