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

8 views (last 30 days)
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])
  1 Comment
Walter Roberson
Walter Roberson on 26 Apr 2021
Also does anyone know how I can automate the legend?
See the DisplayName property that you can use with plot()

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!