Change LineWidth with each loop
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a code that computes different values for variable "component" in each iteration of a for loop and then plots this variable in subplot(3,1,1). With each click/button press I get a new curve added to subplot(3,1,1). I want the last curve that was plotted to stand out by having a thicker LineWidth.
clear all
fs = 10000;
t = 0 : 1/fs : 1;
component = 0;
sig = 0;
N = 10; %Number of iterations
for i = 1:N
f(i) = 2^(i-1);
waitforbuttonpress %button press or click
component = (100/i)*sin(2*pi*f(i)*t); %variable computed with each iteration
sig = component + sig; %ignore this variable
subplot(3,1,1)
plot(t, component, 'color', rand(1,3), 'LineWidth', 2) %variable "component" is plotted with LineWidth = 2
hold on
subplot(3,1,2) %ignore this plot
plot(t,sig, 'LineWidth', 2) %ignore this plot
end
close
clear all
For example, if I already have 4 curves on subplot(3,1,1), each having LineWidth = 0.5 and I press a button, the 5th curve must be added with LineWidth = 2. With the next button press, the 5th curve must change to LineWidth = 0.5 (same as the curves that came before it) and the 6th curve must have LineWidth = 2. This way the most recent curve will stand out.
Any ideas?
0 comentarios
Respuestas (1)
Steven Lord
el 26 de Feb. de 2020
Store the handles to the lines (or find the handles to the lines each time with findobj or findall).
set the LineWidth for all the existing lines to 0.5. [For most of the lines this will be a no-op, but that's okay.]
Finally create the new line with LineWidth 2.
0 comentarios
Ver también
Categorías
Más información sobre Labels and Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!