Plot now showing correctly

I was working on my code like 10 days ago in 2025a, the code is running and the plot is showing correctly. I decided to run again to take some screenshot of my plot but my plot is no longer displaying correctly. If I print the plot, I will see the correct plot on the print dialog but the original plot window is showing up very bad. Screenshot applied. Please any immediate help will be appreciated as this is my school assignment.
My computer is Linux Ubuntu 22.04
clear all; close all; clc;
%% System Parameters
% Physical parameters of the DC motor
Ra = 1.0; % Armature resistance (Ohm)
La = 0.5; % Armature inductance (H)
J = 0.01; % Moment of inertia (Nms^2/rad)
b = 0.1; % Damping coefficient (Nms)
KT = 0.01; % Torque constant (Nm/A)
Ke = 0.01; % Back EMF constant (Nm/A)
K = Ke; % In SI units, Ke = Ki = K
%% Transfer Function Definition
% Open loop transfer function: θ(s)/Ea(s)
% G(s) = K / [(Js + b)(Las + Ra) + K^2]
% Coefficients calculation
num = K;
den_coeff = [J*La, (J*Ra + b*La), (b*Ra + K^2)];
den = den_coeff;
% Create transfer function
G = tf(num, den);
% Display the transfer function
fprintf('Open Loop Transfer Function:\n');
fprintf('G(s) = %.4f / (%.4fs^2 + %.4fs + %.4f)\n', num, den(1), den(2), den(3));
%% Performance Specifications
% Desired specifications:
% - Settling time (Ts) < 2 seconds
% - Percentage Overshoot (PO) < 5%
% - Steady State Error (SSE) < 1%
fprintf('\nDesired Specifications:\n');
fprintf('- Settling time (Ts) < 2 seconds\n');
fprintf('- Percentage Overshoot (PO) < 5%%\n');
fprintf('- Steady State Error (SSE) < 1%%\n\n');
%% Step 1: Open Loop Response
fprintf('=== STEP 1: OPEN LOOP RESPONSE ===\n');
figure(1);
[y1, t1] = step(G);
plot(t1, y1, 'b-', 'LineWidth', 2);
title('Open Loop Step Response');
xlabel('Time (seconds)');
ylabel('Angular Position (rad)');
grid on;
% Calculate performance metrics for open loop
stepinfo_ol = stepinfo(G);
fprintf('Open Loop Performance:\n');
fprintf('Rise Time (Tr): %.4f seconds\n', stepinfo_ol.RiseTime);
fprintf('Settling Time (Ts): %.4f seconds\n', stepinfo_ol.SettlingTime);
fprintf('Peak Overshoot: %.2f%%\n', stepinfo_ol.Overshoot);
% Steady state error calculation (for unit step)
% For Type 0 system: ess = 1/(1+Kp) where Kp = lim s->0 G(s)
Kp_ol = dcgain(G);
ess_ol = 1/(1+Kp_ol) * 100; % Convert to percentage
fprintf('Steady State Error: %.2f%%\n', ess_ol);
fprintf('Comments: Open loop system is unstable or has poor performance\n\n');
Bad Plot
Print Dialog

7 Comments

Your code works correctly here and in MATLAB Online --
clear all; close all; clc;
%% System Parameters
% Physical parameters of the DC motor
Ra = 1.0; % Armature resistance (Ohm)
La = 0.5; % Armature inductance (H)
J = 0.01; % Moment of inertia (Nms^2/rad)
b = 0.1; % Damping coefficient (Nms)
KT = 0.01; % Torque constant (Nm/A)
Ke = 0.01; % Back EMF constant (Nm/A)
K = Ke; % In SI units, Ke = Ki = K
%% Transfer Function Definition
% Open loop transfer function: θ(s)/Ea(s)
% G(s) = K / [(Js + b)(Las + Ra) + K^2]
% Coefficients calculation
num = K;
den_coeff = [J*La, (J*Ra + b*La), (b*Ra + K^2)];
den = den_coeff;
% Create transfer function
G = tf(num, den);
% Display the transfer function
fprintf('Open Loop Transfer Function:\n');
Open Loop Transfer Function:
fprintf('G(s) = %.4f / (%.4fs^2 + %.4fs + %.4f)\n', num, den(1), den(2), den(3));
G(s) = 0.0100 / (0.0050s^2 + 0.0600s + 0.1001)
%% Performance Specifications
% Desired specifications:
% - Settling time (Ts) < 2 seconds
% - Percentage Overshoot (PO) < 5%
% - Steady State Error (SSE) < 1%
fprintf('\nDesired Specifications:\n');
Desired Specifications:
fprintf('- Settling time (Ts) < 2 seconds\n');
- Settling time (Ts) < 2 seconds
fprintf('- Percentage Overshoot (PO) < 5%%\n');
- Percentage Overshoot (PO) < 5%
fprintf('- Steady State Error (SSE) < 1%%\n\n');
- Steady State Error (SSE) < 1%
%% Step 1: Open Loop Response
fprintf('=== STEP 1: OPEN LOOP RESPONSE ===\n');
=== STEP 1: OPEN LOOP RESPONSE ===
figure(1);
[y1, t1] = step(G);
plot(t1, y1, 'b-', 'LineWidth', 2);
title('Open Loop Step Response');
xlabel('Time (seconds)');
ylabel('Angular Position (rad)');
grid on;
% Calculate performance metrics for open loop
stepinfo_ol = stepinfo(G);
fprintf('Open Loop Performance:\n');
Open Loop Performance:
fprintf('Rise Time (Tr): %.4f seconds\n', stepinfo_ol.RiseTime);
Rise Time (Tr): 1.1351 seconds
fprintf('Settling Time (Ts): %.4f seconds\n', stepinfo_ol.SettlingTime);
Settling Time (Ts): 2.0652 seconds
fprintf('Peak Overshoot: %.2f%%\n', stepinfo_ol.Overshoot);
Peak Overshoot: 0.00%
% Steady state error calculation (for unit step)
% For Type 0 system: ess = 1/(1+Kp) where Kp = lim s->0 G(s)
Kp_ol = dcgain(G);
ess_ol = 1/(1+Kp_ol) * 100; % Convert to percentage
fprintf('Steady State Error: %.2f%%\n', ess_ol);
Steady State Error: 90.92%
fprintf('Comments: Open loop system is unstable or has poor performance\n\n');
Comments: Open loop system is unstable or has poor performance
.
Samuel
Samuel on 14 Jul 2025
Moved: Steven Lord on 14 Jul 2025
Yes, but why the error on my local ubuntu installation of 2025a? I won't always be able to work online and I need my plots to come out well. My concern is that It was working just fine last week and now its gone
If I remember correctly, The MathWorks uses Ubuntu here and in MATLAB Online.
ver
------------------------------------------------------------------------------------------------- MATLAB Version: 25.1.0.2952844 (R2025a) MATLAB License Number: 40912989 Operating System: Linux 6.8.0-1019-aws #21~22.04.1-Ubuntu SMP Thu Nov 7 17:33:30 UTC 2024 x86_64 Java Version: Java 1.8.0_292-b10 with AdoptOpenJDK OpenJDK 64-Bit Server VM mixed mode ------------------------------------------------------------------------------------------------- MATLAB Version 25.1 (R2025a) Simulink Version 25.1 (R2025a) 5G Toolbox Version 25.1 (R2025a) 6G Exploration Library for 5G Toolbox Version 25.1.0 (R2025a) Aerospace Blockset Version 25.1 (R2025a) Aerospace Toolbox Version 25.1 (R2025a) Antenna Toolbox Version 25.1 (R2025a) Audio Toolbox Version 25.1 (R2025a) Automated Driving Toolbox Version 25.1 (R2025a) Bioinformatics Toolbox Version 25.1 (R2025a) Bluetooth Toolbox Version 25.1 (R2025a) Communications Toolbox Version 25.1 (R2025a) Computer Vision Toolbox Version 25.1 (R2025a) Control System Toolbox Version 25.1 (R2025a) Curve Fitting Toolbox Version 25.1 (R2025a) DO Qualification Kit Version 25.1 (R2025a) DSP System Toolbox Version 25.1 (R2025a) Database Toolbox Version 25.1 (R2025a) Datafeed Toolbox Version 25.1 (R2025a) Deep Learning Toolbox Version 25.1 (R2025a) Econometrics Toolbox Version 25.1 (R2025a) Embedded Coder Version 25.1 (R2025a) Financial Instruments Toolbox Version 25.1 (R2025a) Financial Toolbox Version 25.1 (R2025a) Fixed-Point Designer Version 25.1 (R2025a) Fuzzy Logic Toolbox Version 25.1 (R2025a) Global Optimization Toolbox Version 25.1 (R2025a) HDL Coder Version 25.1 (R2025a) HDL Verifier Version 25.1 (R2025a) IEC Certification Kit Version 25.1 (R2025a) Image Acquisition Toolbox Version 25.1 (R2025a) Image Processing Toolbox Version 25.1 (R2025a) Industrial Communication Toolbox Version 25.1 (R2025a) Instrument Control Toolbox Version 25.1 (R2025a) LTE Toolbox Version 25.1 (R2025a) MATLAB Coder Version 25.1 (R2025a) MATLAB Compiler Version 25.1 (R2025a) MATLAB Compiler SDK Version 25.1 (R2025a) MATLAB Report Generator Version 25.1 (R2025a) Mapping Toolbox Version 25.1 (R2025a) Medical Imaging Toolbox Version 25.1 (R2025a) Mixed-Signal Blockset Version 25.1 (R2025a) Model Predictive Control Toolbox Version 25.1 (R2025a) Model-Based Calibration Toolbox Version 25.1 (R2025a) Navigation Toolbox Version 25.1 (R2025a) Optimization Toolbox Version 25.1 (R2025a) Parallel Computing Toolbox Version 25.1 (R2025a) Partial Differential Equation Toolbox Version 25.1 (R2025a) Phased Array System Toolbox Version 25.1 (R2025a) Powertrain Blockset Version 25.1 (R2025a) Predictive Maintenance Toolbox Version 25.1 (R2025a) RF Blockset Version 25.1 (R2025a) RF Toolbox Version 25.1 (R2025a) Radar Toolbox Version 25.1 (R2025a) Requirements Toolbox Version 25.1 (R2025a) Risk Management Toolbox Version 25.1 (R2025a) Robotics System Toolbox Version 25.1 (R2025a) Robust Control Toolbox Version 25.1 (R2025a) Sensor Fusion and Tracking Toolbox Version 25.1 (R2025a) SerDes Toolbox Version 25.1 (R2025a) Signal Processing Toolbox Version 25.1 (R2025a) SimBiology Version 25.1 (R2025a) SimEvents Version 25.1 (R2025a) Simscape Version 25.1 (R2025a) Simscape Driveline Version 25.1 (R2025a) Simscape Electrical Version 25.1 (R2025a) Simscape Fluids Version 25.1 (R2025a) Simscape Multibody Version 25.1 (R2025a) Simulink 3D Animation Version 25.1 (R2025a) Simulink Check Version 25.1 (R2025a) Simulink Code Inspector Version 25.1 (R2025a) Simulink Coder Version 25.1 (R2025a) Simulink Control Design Version 25.1 (R2025a) Simulink Coverage Version 25.1 (R2025a) Simulink Design Optimization Version 25.1 (R2025a) Simulink Design Verifier Version 25.1 (R2025a) Simulink Desktop Real-Time Version 25.1 (R2025a) Simulink PLC Coder Version 25.1 (R2025a) Simulink Real-Time Version 25.1 (R2025a) Simulink Report Generator Version 25.1 (R2025a) Simulink Test Version 25.1 (R2025a) Stateflow Version 25.1 (R2025a) Statistics and Machine Learning Toolbox Version 25.1 (R2025a) Symbolic Math Toolbox Version 25.1 (R2025a) System Identification Toolbox Version 25.1 (R2025a) Text Analytics Toolbox Version 25.1 (R2025a) Vehicle Dynamics Blockset Version 25.1 (R2025a) Vehicle Network Toolbox Version 25.1 (R2025a) Vision HDL Toolbox Version 25.1 (R2025a) WLAN Toolbox Version 25.1 (R2025a) Wavelet Toolbox Version 25.1 (R2025a) Wireless HDL Toolbox Version 25.1 (R2025a)
You may need to Contact Support about this problem.
.
I just ran my code on MATLAB online now and i got exactly the same bad plot error on MATLAB online
I ran it again in MATLAB Online just now three times in succession, and it continues to plot correctly every time.
Omar
Omar on 24 Oct 2025
Moved: Dyuman Joshi on 24 Oct 2025
Did you solved it, I have the same problem with Matlab R2025b
@Omar, Can you enter "computer" at the Command Window or provide the info about your computer on which MATLAB is running?
computer
ans = 'GLNXA64'

Sign in to comment.

Answers (1)

IBE PETER
IBE PETER on 29 Oct 2025
Moved: Walter Roberson on 29 Oct 2025

I was able to solve it by using a different linewidth in the plot command. plot(t1, y1, 'b-', 'LineWidth', 2); Change that 2 to like 0.5

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2025a

Asked:

on 14 Jul 2025

Commented:

DGM
on 30 Oct 2025

Community Treasure Hunt

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

Start Hunting!