Axis does not plot in app designer

1 次查看(过去 30 天)
I am making an application in app designer where I use two graphs to show the PWM of a digital controller, the UIAxes of the controller response works fine, but the PWM does not show the graph even when the axes are updated normally.
usada = app.PlacaDropDown.Value;
pcom = app.PuertoCOMEditField.Value;
elcom = strcat('COM', pcom);
app.a = arduino(elcom, usada);
app.parar = false;
app.file_path = uiputfile('*.csv', 'Guardar como');
i = 1;
H1 = 0;
H2 = 0;
selectedTab = app.TabGroup.SelectedTab;
titulo = selectedTab.Title;
switch titulo
case 'P'
K = app.K_P.Value;
t = app.T_P.Value;
q0 = K;
q1 = 0.0;
q2 = 0.0;
case 'PI'
K = app.K_PI.Value;
Ti = app.Ti_PI.Value;
t = app.T_PI.Value;
q0 = K * ( 1 + t/2*Ti );
q1 = -K * ( 1 - t/2*Ti );
q2 = 0.0;
case 'PID'
K = app.K_PID.Value;
Ti = app.Ti_PID.Value;
Td = app.Td_PID.Value;
t = app.T_PID.Value;
q0 = K * (1 + t/2*Ti + Td/t );
q1 = -K * (1 - t/2*Ti + 2*Td/t );
q2 = K*Td/t;
end
while ~app.parar
muestra(i) = i;
lectura1(i) = readVoltage(app.a,'A1')* 25;
lectura2(i) = readVoltage(app.a,'A2')* 25;
if lectura1 >= 40
writeDigitalPin(app.a, 'D7', 1);
else
writeDigitalPin(app.a, 'D7', 0);
end
if lectura2 >= 40
writeDigitalPin(app.a,'D8',1);
else
writeDigitalPin(app.a, 'D8', 0);
end
if app.Q1CheckBox.Value
%Actualizacion del vector de error (etapa 1).
app.e1(1) = app.e1(2);
app.e1(2) = app.e1(3);
app.e1(3) = app.tempRef.Value - lectura1(i);
%Actualizacion del vector de control (etapa 1).
app.u1(1) = app.u1(2);
app.u1(2) = ControlPID(app.u1, app.e1, q0, q1, q2);
H1 = app.u1(2) / 100; %Se mapea el PWM obtenico para enviarlo al arduino.
writePWMDutyCycle(app.a, 'D11', H1);
end
if app.Q2CheckBox.Value
%Actualizacion del vector de error (etapa 2).
app.e2(1) = app.e2(2);
app.e2(2) = app.e2(3);
app.e2(3) = app.tempRef.Value - lectura2(i);
%Actualizacion del vector de control (etapa 2).
app.u2(1) = app.u2(2);
app.u2(2) = ControlPID(app.u2, app.e2, q0, q1, q2);
H2 = app.u2(2) / 100; %Se mapea el PWM obtenico para enviarlo al arduino.
writePWMDutyCycle(app.a, 'D10', H2);
end
format bank;
app.matriz1(1, 1) = muestra(i);
app.matriz1(1, 2) = round(lectura1(i), 2);
app.matriz1(1, 3) = round(lectura2(i), 2);
app.matriz1(1, 4) = round(H1 * 100, 2);
app.matriz1(1, 5) = round(H2 * 100, 2);
writematrix(app.matriz1, app.file_path, 'WriteMode', 'append');
plot(app.grafica_pwm, muestra(i), H2 * 100, muestra(i), H1 * 100);
legend(app.grafica_pwm, 'H2', 'H1');
plot(app.grafica_temp, muestra, lectura2, muestra, lectura1);
legend(app.grafica_temp, 'Lectura2', 'Lectura1');
drawnow;
i = i + 1;
%set(app.inicioButton,'BackgroundColor',[0 0 0],'FontColor',[0.96 0.96 0.96],'Text','Sensando...');
pause(t);
end
function [act] = ControlPID(u, e, q0, q1, q2)
act = u(1) + q0*e(3) + q1*e(2) + q2*e(1);
if act >= 100
act = 100;
elseif act <= 0
act = 0;
end
end
I am grateful for any comments

采纳的回答

Voss
Voss 2024-4-15
You are plotting scalars:
plot(app.grafica_pwm, muestra(i), H2 * 100, muestra(i), H1 * 100)
scalars don't show up unless they have a marker.
For example:
figure
plot(2,1) % nothing
figure
plot(2,1,'*') % a point appears in the plot
So maybe you should plot with a marker.
However, you may want to be indexing H1 and H2 in your calculations, similar to lectura1 and lectura2, i.e., calculate H1(i) and H2(i). Then plot those vectors
plot(app.grafica_pwm, muestra, H2 * 100, muestra, H1 * 100);
which would be consistent with the other plot call, which plots vectors:
plot(app.grafica_temp, muestra, lectura2, muestra, lectura1);
  2 个评论
juan david daza perez
thank you very much, your answer helped me a lot
Voss
Voss 2024-4-20
编辑:Voss 2024-4-21
You're welcome! Any questions, please let me know.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by