Using tic toc to change a value every 30 seconds?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am writing a code that creates a bar graph using data created in a matrix. Every 30 seconds, I want to multiply the value of one of the bar graphs by a value. The distortion will increase by 0.02 every time. For example, in the first 30 seconds, the bar graph will show the bar at a normal value (100%), in the second 30 seconds, the bar graph will show the bar at its value times 1.02 (102%), in the third 30 seconds, the bar graph will show the bar at its value times 1.04 (104%). This increases all the way up to 114%, then the distortion decreases from 114% to 112% to 110% etc. back to zero. I have written the code that is capable of doing this and have provided it below (this is all included in a while loop that pulls the data for the bar graphs; "tic" is written before the while loop begins). However, at the beginning of the code and at the end of the code (after it reaches 100%), I want to include a part where the bar graph is at its original value for 2 straight minutes (100% or an alpha value of 0 for 120 seconds). How would I do this if my alpha value is set to increase by 0.02 every time?
if toc > interval
if alpha <= 1
distortion = abs(distortion);
elseif alpha >= 1.14
distortion = -abs(distortion);
end
alpha = alpha + distortion;
tic;
end
array_size = size(M);
M(array_size(1)+1,:) = [b e Rsteplength Lsteplength];
if array_size(1) <= row_count
pause(sampling_time);
continue;
else
row_count = array_size(1);
end
current_left = M(row_count,3);
current_right = M(row_count,4);
if current_left > last_left
left_bar = current_left*alpha;
elseif current_left < current_right
left_bar = 0;
end
if current_right > last_right
right_bar = current_right*alpha;
elseif current_right < current_left
right_bar = 0;
end
lstep_length = [left_bar, right_bar];
bargraph = bar(lstep_length);
ylim([0,1000])
last_left = current_left;
last_right = current_right;
pause(sampling_time);
end
2 commentaires
Geoff Hayes
le 28 Mar 2016
Modifié(e) : Geoff Hayes
le 28 Mar 2016
jgg has it right. A timer would be a better way to do this. You could then delay the start of the timer by two minutes (when at 100%).
Réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!