I have several folders. In every folder is 1 file called Data. Every file has structures, one of those is Data.ensemble. From this structure I extract the temperature (column 9, see question Hierarchy between and / or in an if statement) . My problem now is within my loop, to extract and save this temperature in a structure every iteration. For example, if I have 10 folders and 10 files. I want
Temperature.1=[12 15 10...]
Temperature.2=[20 30 11...]
...
Temperature.10=[15 26 27...]
and these will all be different sizes. The extraction works fine, it is saving it that is a problem. I tried the following code with help from https://nl.mathworks.com/matlabcentral/answers/304405-create-a-struct-iteratively
folders =struct2cell(dir(Pathfolders)); %Pathfolders is the path to the folders
NaamFolders=string(char(folders(1,:))); %make a list of all the foldernames
lenNF=length(NaamFolders);
for i = 1:lenNF
Map=char(NaamFolders(i,1)); % Give me the name of the first , second, ... folder
Pathfiles=[Path,'\',Map,'\','*_new.mat']; %Make the path to the files that end with _new.mat (in my case only 1)
files =struct2cell(dir(Pathfiles)); %Select all files that end with _new.mat (in my case only 1)
NaamFiles=char(files(1,:)); % Make a list of the names of all those files (in my case only 1)
FilePath=[Path,'\',Map,'\',NaamFiles]; %create path to that 1 file
Data=load(FilePath); %load that file
[lenData,lenvariables]=size(Data.ensemble) % determine the size of the file structure called ensemble
idx=NaamFolders{i} %Select the name you want to call your structure in the variable you want to create
index = ismember(Data.ensemble(:,8),[10,20,30]) & Data.ensemble(:,5) == 12; %determine the index where column 5 == 12 and column 8 == 10 or 20 or 30
RightData = Data.ensemble(index,:) % this the data where the previous comment is true
Temperature.idx=RightData(:,9) % this line does not work. For every iteration, create a new structure within temperature that extracts column 9 from RightData.
end
It is the last line that does not work and gives the error
Unable to perform assignment because dot indexing is not supported for variables of this type.
Error in ExtractTrajectory (line 36)
Temperature.idx=RightData(:,9)