Info

This question is closed. Reopen it to edit or answer.

Checking if a Field exists in a structure, nested in values in a cell

1 view (last 30 days)
Hello,
I don't know how to get the right Data from the attached file and would appreciate some help.
The Data I need depends on the amount of fields the Data has in Messung{1, 2}.Data.MeasuredData
The Structure lies in a cell with a view values.
I tried an if Code with an logical operator but this doesnt work with structures. So i found on the web the isField function but that doesnt work either
a = isfield(Messung{1 ,2}.Data.MeasuredData,103)
a =
logical
0

Answers (1)

Image Analyst
Image Analyst on 14 Jun 2020
Edited: Image Analyst on 14 Jun 2020
See if this does what you want:
s = load('2020-06-10_ 16.28.25 Uhr_Messblock_02012_LNr_51.mat')
Messung = s.Messung{1 ,2}.Data
str = Messung.Root
strMeasuredData = Messung.MeasuredData
for k = 1 : length(strMeasuredData)
thisStructure = strMeasuredData(k);
if thisStructure.Total_Samples == 0
fprintf(' Skipping structure %d because there are zero samples in it.\n', k);
continue;
end
fprintf('Using structure %d because there are %d samples in it.\n', k, thisStructure.Total_Samples);
% Now do something with thisStructure
end
  1 Comment
Simon Preuss
Simon Preuss on 15 Jun 2020
The Code works fine but I think I should explain a little bit more what I need.
This is the code where I want to implement it in
for i = 1:34
Zaehler{i}= i-2;
end
dire='C:\Users\simon\Desktop\Auswertung\Matlab_Simon\HA3_ATE_HA_konvertierte_Daten\AK_Master';
color={[0 0 0] [0/255 158/255 234/255] [147/255 16/255 126/255] [114/255 120/255 121/255] [192/255 192/255 192/255] [84/255 55/255 138/255] [0/255 125/255 64/255] [255/255 0/255 0/255] [238/255 127/255 0/255] [106/255 176/255 35/255] [0/255 48/255 94/255] [0/255 125/255 64/255] [0/255 106/255 179/255] [0/255 158/255 224/255] [0/255 125/255 64/255]};
ziel1='C:\Users\simon\Desktop\Auswertung\Matlab_Simon\HA3_ATE_HA_Erstauswertung\AK_Master';
zieldir=dir(ziel1);
data1=dir(dire);
i=1;
for i=1:length(data1)-2
data2{i}=dir(strcat(dire,'\',data1(i+2).name));
end
u=1;
i=1;
for i=1:length(data1)-2
for u=1:length(data2{i})-2
load(strcat(dire,'\',data1(i+2).name,'\',data2{i}(u+2).name))
%geht in den Ordner, Unterordner, Unterordner und schreibt dann den Namen
%der abzuspeichernden Datei
filenameAr1pM=strcat(ziel1,'\',data1(i+2).name,'\','Bremsdruck_und_Bremsmoment','\',data2{i}(u+2).name(36:end-4),'_','Msng','_',num2str(Zaehler{u+2}));
filenameAr1n=strcat(ziel1,'\',data1(i+2).name,'\','Drehzahl','\',data2{i}(u+2).name(36:end-4),'_','Msng','_',num2str(Zaehler{u+2}));
filenameAr1T=strcat(ziel1,'\',data1(i+2).name,'\','Temperatur','\',data2{i}(u+2).name(36:end-4),'_','Msng','_',num2str(Zaehler{u+2}));
Pos_p = length(Messung{1, 2}.Data.MeasuredData)-30;
Pos_M_re = length(Messung{1, 2}.Data.MeasuredData)-32;
Pos_M_li = length(Messung{1, 2}.Data.MeasuredData)-31;
I have many measurements and for each measurement the variable Messung gets new values. The data I need is taken from the code with the last 3 lines for each measurment (Pos_p, Pos_M_re, Pos_M_li).
The problem is that the structure sometimes has 120, 103 or 86 fields. Depending on the length of the structure, the correct data is in a specific field (for a length of 120 the Data is in field 107, for a length of 103 in field 73 and for a length of 86 in field 56).
I would now like to know how, depending on the length of the structure, I can get the right data to make my evaluation.

Community Treasure Hunt

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

Start Hunting!