Open multiple .csv files, process and save them in a structure
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
JoKi
el 8 de Jul. de 2020
Comentada: JoKi
el 8 de Jul. de 2020
Hello guys,
im very new to Matlab and have to code my own program to analyse some data. I need to open multiple .csv files (done that with uigetfile), filter them for the needed data (which is in column 7 and starts at row 31, i have put in a photo of how my data looks). My problem is that i cant save the files the way i want after i have opened them. I need to filter and plot the extracted data afterwards. The code i have so far works but is only saving the first file.
My Plan was to save each data with the loop in a structure so that i can access them later. If there is another way to save the data, im fine with it too, doesnt have to be with a structure i just thought this could work.
[filename,pathname] = uigetfile('*.csv;','MultiSelect',"on");
for i = 1,length(filename)
filen = filename(1,i);
filepath=fullfile(pathname, filename);
fid = fopen (filepath{i});
%[file,path]=uigetfile('*.csv');
A = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s','Delimiter',';');
%Umwandeln von Cell --> String
B=string([A{:}]);
%',' durch '.' ersetzen
B=replace(B,',', '.'); % ',' durch '.' ersetzen
% Aufteilen in Header und Messdaten
Daten.Header=B(1:30,:);
Daten.Messdaten=str2double(B(31:end,7));
end
I am using the Matlab AppDesigner.
Since this is my first question here i hope this is enough information.
0 comentarios
Respuesta aceptada
Stephen23
el 8 de Jul. de 2020
You need to fix this line otherwise your loop will only iterate once:
for i = 1:length(filename)
% ^ this must be a colon!
You also need to use indexing to allocate to the output array on each loop iteration, e.g.:
Daten(i).Header = ...
Daten(i).Messdaten = ...
Read more about structure arrays:
Más respuestas (0)
Ver también
Categorías
Más información sobre Standard File Formats 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!