Store values in an array from loop
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Bob Thompson
2020-2-24
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
2 个评论
Bob Thompson
2020-2-25
Sure. If you establish a variable like HDA_names (I recommend doing a cell or string array, rather than a concat like that) then you should just be able to use the same index setup and include one more fprintf line in your current loop.
HDA_names = {'Asn42_OH3p' 'Asp44_O3p' 'Lys74_OH4p' ... };
% Rest same as before
for X = ...
% Again same as before
% Include this next line as the first of your fprintf lines
fprintf('\c',HDA_names{X}) % There is a way to underline the output, I believe,
% but I don't remember it off the top of my head.
% I recommend looking up fprintf for more details
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!