Open multiple .csv files, process and save them in a structure

11 vues (au cours des 30 derniers jours)
JoKi
JoKi le 8 Juil 2020
Commenté : JoKi le 8 Juil 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.

Réponse acceptée

Stephen23
Stephen23 le 8 Juil 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:
  1 commentaire
JoKi
JoKi le 8 Juil 2020
Ahh thanks, so far it works now.
I have tried to name it Daten.Header(i) before, didnt know i had to put the (i) there.
Thanks alot!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Standard File Formats dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by