MATLAB: Store values in an array from loop

arraydataloopstorevectors

Hello everyone,
I have a vector HDA which is associated to different lists of angles.
For each list (a1, b1, … etc.) i need to convert all the values in radians and make the circular average together with the standard
deviation with the functions Circ_ang2rad, circ_mean and circ_std.
Then I print the values. Clearly, I don't know how to make a proper loop so if anybody is willing to help I would be most grateful!
It would be also nice to print the result with a 'name' associated to it so that one could understand which result refers to which angle.
a1 = Asn42OH3p(:,1); %List of angles from traiectory for Asn42
b1 = Asp44O4p(:,1); %List of angles from traiectrory for Asp44
...and so on
HDA = [a1 b1 c1 d1 e1 f1 g1];
for X = HDA;
A_rad = circ_ang2rad(X);
A_bar = circ_mean(A_rad);
[s_A s0_A] = circ_std(A_rad);
fprintf('X torsion');
fprintf('\n')
fprintf('Mean resultant vector: \t%.2f \t%.2f\n', circ_rad2ang([A_bar]));
end

Best Answer

I'm not sure what you mean by printing the 'name' associated to a data set, but there are my modifications to what you have setup.
a1 = Asn42OH3p(:,1); %List of angles from trajectory for Asn42
b1 = Asp44O4p(:,1); %List of angles from trajectrory for Asp44
...and so on
HDA = [a1 b1 c1 d1 e1 f1 g1];
A_rad = circ_ang2rad(HDA); % Can remove this from the loop, as I believe the function operates on all
% elements in the input array individually.
for X = 1:size(A_rad,2); % Work through all columns of A_rad, works with one data set per loop.
A_bar(X) = circ_mean(A_rad(:,X)); % Find average for current data set. Store in array
[s_A(:,X) s0_A(:,X)] = circ_std(A_rad(:,X)); % Standard deviation for each data set.
% You might need to adjust the indexing if the outputs above (I don't know that they're all arrays)
fprintf('X torsion');
fprintf('\n')
fprintf('Mean resultant vector: \t%.2f \t%.2f\n', circ_rad2ang([A_bar]));
end