How to read in a file automatically through loop?

4 views (last 30 days)
Hello everyone!
I need your help in finding a way to read in a a file each iteration.
My Folder looks like that:
and I want that each time it reads the file in order.
For example, for j=1--> reads in the first file
for j=2--> reads in the second file
.....and so on.
Until now, I used to read in the files every time manually,but I would like if my script could do it on its own to save time.
I appreciate any help :)
  12 Comments
Ifigenia Aslanidou
Ifigenia Aslanidou on 25 Aug 2019
I realised whichmight be causing the trouble: the S returns a Matrix : N x 6 instead of the measurements list..(struct)
Ifigenia Aslanidou
Ifigenia Aslanidou on 25 Aug 2019
Ok now it worked!
Script:
clear all;
%% Pre-allocate the variables that will save ALL of the data
Preallocating_variables_save_all_data;
P = 'C:\Users\aslan\OneDrive\Desktop\Studienarbeit 2019\Messungen';
D = dir(fullfile('Messungen','*.mat')); %I dont know what the problem was because with S... instead of D it caused the troubles, when I ran it was a matrix,when I typed it it in command it... was a list
for j=1:6
%------------------------------INPUTS---------------------------------%
% Datei einlesen (Array "OUTPUT")
F = fullfile('Messungen',D(j).name); %replaced P with 'Messungen' (how the meas. file is... named after
T = load(F);
OUTPUT = T.OUTPUT;

Sign in to comment.

Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!