How to Concetanate Arrays in a Struct?

Hi. I want to chain the two arrays together in a 1x2 struct. In the command window, this also works perfectly (either via vertcat or via [...; ...]). However, it does not work after integration into the code. Any ideas?
Here is the Code ( I want to connect the different Arrays from the Field "Durchschnittswert") :
for idx_act_Channel=1:size(idx_Channel,2)
% ein Resultat --> Durchschnitt innerhalb dieses Intervalls
MasterResult(idx_loopi).Durchschnittswert(counter,idx_act_Channel)= mean(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
MasterResult(idx_loopi).Maximalwert(counter,idx_act_Channel)= max(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
MasterResult(idx_loopi).Minimalwert(counter,idx_act_Channel)= min(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
%Umwandlung in Tabelle
Modus = struct2table(MasterResult);
%Aneinanderreihen der Daten der eingelesenen Files
%(vertikal) ! - aber kann nicht integriert werden?
%ModusMio = vertcat(Modus.Durchschnittswert{1,1}, Modus.Durchschnittswert {2,1}, Modus.Durchschnittswert {3,1});
%vertcat (Modus.Durchschnittswert{1,1}, Modus.Durchschnittswert {2,1}, Modus.Durchschnittswert {3,1});
end
And this is the Struct

 Accepted Answer

You were close with your commented code.
%see what this returns?
MasterResult.Durchschnittswert
%you can concatenate that comma separated list:
MergedData=vertcat(MasterResult.Durchschnittswert);

8 Comments

+1, :p thought to answer just to flaunt my german skills xD but you beat me to it!
Thanks. I'm Dutch, so long words don't scare me ;)
Wow didn't know that cool!
Thanks for your answer, it works completely fine in the Command Window and is exactly what I want to produce, but I have Problems again while integrating it into my Code. I'm getting the error : Dimensions of arrays being concatenated are not consistent.
for i=1:size(TimeAxis,1)
% Wert, wo man sich gerade befindet - Startzeit
ActDelta=TimeAxis(i)-IntervalStartzeit;
% Falls die Differenz von aktuellem Wert und Startzeit größer
% gleich der Intervallgrenze ist, dann:
if ActDelta>=SplitTime
IntervalStartzeit=TimeAxis(i);
% Heruasgabe für aktuellen Channel - bei Durchlauf aller 10
% Channel
for idx_act_Channel=1:size(idx_Channel,2)
% ein Resultat --> Durchschnitt innerhalb dieses Intervalls
MasterResult(idx_loopi).Durchschnittswert(counter,idx_act_Channel)= mean(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
%MasterResult(idx_loopi).Maximalwert(counter,idx_act_Channel)= max(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
%MasterResult(idx_loopi).Minimalwert(counter,idx_act_Channel)= min(test(idx_loopi).Channels(idx_act_Channel).Data(idxStart:i));
MergedData=vertcat(MasterResult.Durchschnittswert);
%Umwandlung in Tabelle
%Modus = struct2table(MergedData);
%Aneinanderreihen der Daten der eingelesenen Files
%(vertikal) ! - aber kann nicht integriert werden?
%ModusMio = vertcat(Modus.Durchschnittswert{1,1}, Modus.Durchschnittswert {2,1}, Modus.Durchschnittswert {3,1});
%vertcat (Modus.Durchschnittswert{1,1}, Modus.Durchschnittswert {2,1}, Modus.Durchschnittswert {3,1});
end
idxStart=i;
counter=counter+1;
end
end
Do I position the command incorrectly?
Since you are filling the variable inside that loop, I don't think that is the correct line to put that code.
I suspect you should put that code after your outer loop.
Now it works! Thanks for your advice (stupid from me) :)
No problem, happy to help

Sign in to comment.

More Answers (0)

Categories

Asked:

on 4 Jun 2020

Commented:

Rik
on 4 Jun 2020

Community Treasure Hunt

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

Start Hunting!