Only last iteration of for loop
Mostrar comentarios más antiguos
Hello,
I am running a for loop in a while loop in app designer which may not be good programming practice but I really need it to run. I am ploting a bar chart in the for loop because i need various colors for different bars. * while loop because am constantly reading serial data from a com port using the serial port fronctions.
Only the last bar is plotted when i run the code. Displaying b on the gui is always 3. I fixed b to 2 and the second bar showed up. I would be very happy to get your ideas on y this is happening. Not just for the code to run but also for future reference. Thanks
Below is my code
properties (Access = public)
% Battery represenstation
Batteries = reordercats(categorical({'Battery1','Battery2','Battery3'})); % x values
y = [Volt1, Volt2, Volt3]; % y Values
clr = [0.2 0.71 0.3; 0.25 0.55 0.79; 0.9 0.1 0.14]; % colors
end
myBar = zeros((lenth(Batteries)));
while(1)
for b = 1:length(y)
app.BEditField.Value = b; % display b on GUI
% Plot one single bar as a separate bar series.
myBar(b) = bar(app.UIAxes, app.Batteries(b), y(b));
% Apply the color to this bar series.
set(myBar(b),'FaceColor', app.clr(b,:));
% values on each bar
text(app.UIAxes, b:b, y(b)', num2str(y(b)','%0.2f'),'HorizontalAlignment','center','VerticalAlignment','bottom')
hold on ;
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!