How to solve a problem with the generation of multiple-colored segments on one line in Matlab plot
Afficher commentaires plus anciens
Hello everyone, I am trying to plot a graph where there are colored segements on one line . The segements are colored based on a vector that has values 1,2 and 3. The vectror size is kind of big size 1X155879. The time length of the line is around 1600 (in sec) The problem is that at the begining, the code runs well for small vectors but for my current mentioned vector, when I run the code, it runs only at the first 150 points of time and then the simulation becomes very slow and the graph disappears and no output is shown. is this because the data vector is very large or not ? and how can I generate this graph properly for that big data vector (whether using my method or if there is a better way).
P.S: PC specs : Windows 11 Pro, 64Gb RAM, i7-14700K RTX4070
logic_outputs = {[1 2 3 2 1 3 2 2 2 1], [3 1 1 1 3 3 3 1 1 1],[2 1 3 2 3 2 3 1 1 1]};
%logic_outputs = {[randi([1, 3], 1,155879)]};
num_lines = length(logic_outputs);
% Create a time vector
time_vector = linspace(0, 1600, length(logic_outputs{1}) +1);
% Set the heights for each line
line_heights = [568, 780, 1500];
% Set axis limits and labels
xlim([0 1600]);
%ylim([-1 1]); % Adjust as needed
xlabel('Time (seconds)');
ylabel('Segment Status');
% Add colored segments based on logic output for each line
for line_index = 1:num_lines
logic_output = logic_outputs{line_index};
for i = 1:length(logic_output)
color = getColor(logic_output(i)); % Define getColor function based on your color-coding
plot([time_vector(i), time_vector(i+1)], [line_heights(line_index); line_heights(line_index)], 'Color', color, 'LineWidth', 10);
hold on
end
end
% Function to determine color based on logic output
function color = getColor(output)
switch output
case 1
color = [0, 1, 0]; % green (RGB values)
case 2
color = [1, 1, 0]; % yellow
case 3
color = [1, 0, 0]; % red
otherwise
color = [0, 0, 0]; % black (default)
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

