how to process multiple file in matlab
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Siddharth Pande
el 5 de Abr. de 2014
Comentada: Thiago de Aquino Costa Sousa
el 18 de Sept. de 2022
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 comentarios
Respuestas (2)
Image Analyst
el 5 de Abr. de 2014
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
12 comentarios
Thiago de Aquino Costa Sousa
el 17 de Sept. de 2022
Walter Roberson
el 17 de Sept. de 2022
No, Image Analyst does not accept direct contacts.
Thiago de Aquino Costa Sousa
el 17 de Sept. de 2022
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 comentarios
Thiago de Aquino Costa Sousa
el 18 de Sept. de 2022
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
el 18 de Sept. de 2022
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?
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!