Colour coding for different time intervals within a plot

조회 수: 7 (최근 30일)
Adil Saeed
Adil Saeed 2022년 8월 26일
답변: Adil Saeed 2022년 8월 26일
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')
Warning: Ignoring extra legend entries.
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

답변 (1개)

Adil Saeed
Adil Saeed 2022년 8월 26일
plot(Time_Vector(1:Cumalative_Sum_of_Impacts(1)),Source_Level(1:Cumalative_Sum_of_Impacts(1)),'b.','markersize',3)
plot(Time_Vector(Cumalative_Sum_of_Impacts(1):Cumalative_Sum_of_Impacts(2)),Source_Level(Cumalative_Sum_of_Impacts(1):Cumalative_Sum_of_Impacts(2)),'g.','markersize',3)
plot(Time_Vector(Cumalative_Sum_of_Impacts(2):Cumalative_Sum_of_Impacts(3)),Source_Level(Cumalative_Sum_of_Impacts(2):Cumalative_Sum_of_Impacts(3)),'r.','markersize',3)
plot(Time_Vector(Cumalative_Sum_of_Impacts(3):Cumalative_Sum_of_Impacts(4)),Source_Level(Cumalative_Sum_of_Impacts(3):Cumalative_Sum_of_Impacts(4)),'c.','markersize',3)
plot(Time_Vector(Cumalative_Sum_of_Impacts(4):Cumalative_Sum_of_Impacts(5)),Source_Level(Cumalative_Sum_of_Impacts(4):Cumalative_Sum_of_Impacts(5)),'m.','markersize',3)
plot(Time_Vector(Cumalative_Sum_of_Impacts(5):Cumalative_Sum_of_Impacts(6)),Source_Level(Cumalative_Sum_of_Impacts(5):Cumalative_Sum_of_Impacts(6)),'y.','markersize',3)
I found a very long winded approach for those interested

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by