Change colour of line graph once a value is reached
Ältere Kommentare anzeigen
Hello guys,
What I am trying to do is plot a line graph but when a certain value is reached I want the line to change colour just for the segment after the point was reached. The only way I found to do it is with an animation, the problem is that it is really slow and I don't care for the animation, I just want the graph to show the change in colour.
close all
clear
clc
format long g
figure('Name', 'Relative RMSD of alpha and beta structures');
clf();
hold on;
ylim([0 1]);
a = load(['12to17_alpha4.dat']);
b = load(['12to17_beta4.dat']);
title('\fontsize{16}Relative RMSD');
rel_rmsd = a./(a+b);
xseg = [a(1:end-1,1),a(2:end,1)];
yseg = [rel_rmsd(1:end-1,2),rel_rmsd(2:end,2)];
c='black';
for i=1:(length(rel_rmsd)-1)
h = plot(xseg(i,:),yseg(i,:),'-','LineWidth',1, 'color',c);
if(rel_rmsd(i,2)<0.25)
c='red';
end
if(rel_rmsd(i,2)>0.75)
c='blue';
end
drawnow;
end

This results in what I want, but like I said it is extremely slow. Especially if I have more datasets, and wanted to know if anyone knows what else I could do.
Thank you.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Animation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!