Plot now showing correctly

조회 수: 41 (최근 30일)
Samuel
Samuel 2025년 7월 14일
댓글: DGM 2025년 10월 30일
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
Omar
Omar 2025년 10월 24일
이동: Dyuman Joshi 2025년 10월 24일
Did you solved it, I have the same problem with Matlab R2025b
Sam Chak
Sam Chak 2025년 10월 29일
@Omar, Can you enter "computer" at the Command Window or provide the info about your computer on which MATLAB is running?
computer
ans = 'GLNXA64'

댓글을 달려면 로그인하십시오.

답변 (1개)

IBE PETER
IBE PETER 2025년 10월 29일
이동: Walter Roberson 2025년 10월 29일

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by