MATLAB Answers

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

7 views (last 30 days)
JoKi on 8 Jul 2020
Commented: JoKi on 8 Jul 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});
A = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s','Delimiter',';');
%Umwandeln von Cell --> String
%',' durch '.' ersetzen
B=replace(B,',', '.'); % ',' durch '.' ersetzen
% Aufteilen in Header und Messdaten
I am using the Matlab AppDesigner.
Since this is my first question here i hope this is enough information.


Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 8 Jul 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 Comment

JoKi on 8 Jul 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!

Sign in to comment.

More Answers (0)

Translated by