MATLAB: How to read data of files which are in the same folder

importdataread data filesread data foldersubscripted assignment between dissimilar structures

Hi all,
I've been searching on the internet without any succeed…
  1. I want to read files which are in a directory and then read data contaiedn in these files (there are columns).
  2. Below is my script :
cd 'C:\Users\'
folder=('C:\Users\')
txt=dir(fullfile('dry','*.txt'))
% creation of a matrice that contains paths of files
for i=1:length(txt)
fileName(i,:)=fullfile(folder,txt(i).name)
end
% reading of data which is contained in these files
for i=1:length(fileName)
M(i,:)=importdata(fileName(i,:))
end
Very easy but it doesn't work … It says : "Subscripted assignment between dissimilar structures."
Thanks for your help ! Florian

Best Answer

Many thanks it works !
But so sorry, there's a new error I'm trying to fix from an hour. Because of a header, I've coded as below : delimiterIn=' '; headerLines=11; M=[] ;
for i=1:length(txt)
A=importdata(txt(i).name,delimiterIn,headerLines);
M=[M A];
end
Then I'm trying to view data by writing M.data(1,1) for instance and then I get this message : "Field reference for multiple structure elements that is followed by more reference blocks is an error."
Thank you so much for your help ! Florian