Colour coding for different time intervals within a plot
Show older comments
I need different colours for different time intervals within my figure. so the x axis is a time vector, that is a cell of combinations of different doubles. the coding for this is shown below:
%Number of Positions and Impacts
Impacts = [50, 60, 75, 375, 420, 360];
Total_Number_of_Impacts = sum(Impacts);
Cumalative_Sum_of_Impacts = cumsum(Impacts);
%Time
Time = 5400;
Interval = 900;
Time_Interval_Vector = 0:Interval:Time;
j = numel(Time_Interval_Vector);
Time_Vector_Pieces = cell(1, j-1);
for Iter = 1:j-1
Inc = Interval/Impacts(Iter);
Time_Vector_Pieces{Iter} = Time_Interval_Vector(Iter):Inc:(Time_Interval_Vector(Iter+1)-Inc);
end
Time_Vector = [Time_Vector_Pieces{:}];
As you can see from the variable Time_Vector_Pieces this is where all the different doubles are stored each representing a time inerval. so what i need is for each of these pieces / intervals to be shown as a different colour on my figure to be able to differentiate between each time interval.
Source_Level = zeros(1,Total_Number_of_Impacts);
for i = 1:Total_Number_of_Impacts
%Source Level Step Up
if i<=Cumalative_Sum_of_Impacts(1)
Source_Level(i) = 200 ;
else
Source_Level(i) = 210;
end
end
%RECEIVE LEVEL MODEL
figure
set(plot(Time_Vector,Source_Level,'.'),'markersize',3)
title('Sound Exposure Graph (SEL)')
xlabel('Time (s)')
ylabel('Sound Exposure Level (SEL) (dB)')
legend({'Individual Strike Recieve Level (dB re μPa^2s)','Individual Strike Source Level (dB re μPa^2s-m)','Cumalative SEL Level (dB re μPa^2s)'},'Location','east')
SN: i havent included all the plots on the figure as the code would be too long. i will just assume for the other plots it would be the same method
Answers (1)
Adil Saeed
on 26 Aug 2022
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!