Plot now showing correctly

46 Ansichten (letzte 30 Tage)
Samuel
Samuel am 14 Jul. 2025
Kommentiert: DGM am 30 Okt. 2025
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 Kommentare
Omar
Omar am 24 Okt. 2025
Verschoben: Dyuman Joshi am 24 Okt. 2025
Did you solved it, I have the same problem with Matlab R2025b
Sam Chak
Sam Chak am 29 Okt. 2025
@Omar, Can you enter "computer" at the Command Window or provide the info about your computer on which MATLAB is running?
computer
ans = 'GLNXA64'

Melden Sie sich an, um zu kommentieren.

Antworten (1)

IBE PETER
IBE PETER am 29 Okt. 2025
Verschoben: Walter Roberson am 29 Okt. 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

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by