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

12 ビュー (過去 30 日間)
JoKi
JoKi 2020 年 7 月 8 日
コメント済み: JoKi 2020 年 7 月 8 日
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.

採用された回答

Stephen23
Stephen23 2020 年 7 月 8 日
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 件のコメント
JoKi
JoKi 2020 年 7 月 8 日
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!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStandard File Formats についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by