Change plot line style/colours for each variable and iteration of loop

7 次查看(过去 30 天)
Hi, my code below takes values for different muscles in different condition. Does anyone know how I can change my plot line colours and styles so when my figure is created it is easy to tell which line is for which muscle in each condition.
I have 8 muscles and 3 conditions.
Maybe the colours for each muscle would be different and the the line style for each condition will be different (i.e, line, dashed and stars) ?
Also does anyone know how I can automate the legend?
I have attached a picture of my current graph
for i=1:length(mod_dirs)
%% ----------------------------------------------------MA data
% read the MomentArm (MA) data
filename = [ base_dir mod_dirs{i} '\MA_MTL\' 'right_hip_muscle_flexion_MA.sto'];
variables = { 'time','add_mag1_r','add_mag2_r','gem_r','glut_med1_r','glut_min1_r','glut_min2_r','grac_r','quad_fem_r' };
[ data, var_names, info ] = read_select_opensim_data(filename, variables);
time = data.matrix(:,1);
ma_flexion = data.matrix(:,2:8);
ma_flexion_cm=ma_flexion*100;
[cycle_time,TN_ma_flexion]=normalise_data_points(time,ma_flexion_cm,t_cycle_start,t_cycle_end);
% create a plot of the MA of a selected muscle around the flex/ext axis
h1=figure(100);hold on;
plot(cycle_time, TN_ma_flexion);
xlabel('Time [%gait cycle]');
ylabel('Muscle moment arms [cm]');
title({'Adductor moment arms',' during walking'});
legend( );
%'sw_+0.00' , 'sw_+0.01', 'sw_+0.06'
set(h1,'Position',[10 10 500 500])

采纳的回答

Steven Lord
Steven Lord 2021-4-26
See the colororder function and/or the ColorOrder and LineStyleOrder axes properties.
  4 个评论
Steven Lord
Steven Lord 2021-4-26
That's a property of axes objects. See the first section of the documentation page to which I linked.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by