【问题标题】:What is my matlab plot doing?我的 matlab 绘图在做什么?
【发布时间】:2014-02-20 04:30:09
【问题描述】:

我正在尝试绘制一些基本图表,时间与速度、时间与加速度、速度与加速度,但我不明白为什么这些数字会出现在每张图表上。我尝试通过几种方法更改标签,但似乎并没有让它们消失。

clc
clear

disp('Jack Abdo');
disp('Engr Course 297 12441');
disp('Matlab Homework 8 problem #4');
disp('This script graphs output data from a UDP');

ourinput = [0 0];
ourinput(1) = input('Please enter the beginning time.');
ourinput(2) = input('Please enter the ending time.');

time = [ourinput(1):5:ourinput(2)]
velocity = 0.00001*time.^3 - 0.00488*time.^2 + 0.75795*time + 181.3566
acceleration = 3 - 0.000062*velocity.^2

subplot(5,1,1);
plot(time,velocity);
xlabel(time);
ylabel(velocity);
grid;
title('Velocity vs Time');
set(gca,'XTick',0:30:120)
set(gca,'YTick',180:10:220)

subplot(5,1,2);
plot(time,acceleration);
xlabel(time);
ylabel(acceleration);
grid;
title('Acceleration vs Time');
set(gca,'XTick',0:30:120)
set(gca,'YTick',0:5:1)

subplot(5,1,1);
plot(velocity, acceleration);
xlabel(velocity);
ylabel(acceleration);
grid;
title('Acceleration vs Velocity');
axis auto; 

【问题讨论】:

  • 最后不正确的是我忘记了关于时间、加速度和速度的引号。

标签: matlab graph


【解决方案1】:

认真编写代码真的很重要。

我会指出一些东西-

velocity = 0.00001*time.^3 - 0.00488*time.^2 + 0.75795*time + 181.3566

如果要将数组与标量相乘,请使用 .* 符号,即 0.75795.*time

因为标签应该是字符串,所以它应该是 xlabel('Velocity'); 我相信否则它会将整个数组速度设置为 xlabel 这会导致您的问题

即使您有 3 个子图,您也将图形分成 5 个子图,因此您的大部分窗口都是空的。让它subplot(3,1,1)

现在作为绘制了很多时间序列的人,我建议不要预先定义时间轴。尝试使用set(gca,'XTick',[min(time):5:max(time)]);

在每条语句后加分号,除非你想明确输出。 无论如何,这就是您可能一直在寻找的东西。请仔细检查您的代码

disp('Jack Abdo');
disp('Engr Course 297 12441');
disp('Matlab Homework 8 problem #4');
disp('This script graphs output data from a UDP');

ourinput = [0 0];
ourinput(1) = input('Please enter the beginning time.');
ourinput(2) = input('Please enter the ending time.');

time = [ourinput(1):5:ourinput(2)];
velocity = 0.00001.*time.^3 - 0.00488.*time.^2 + 0.75795.*time + 181.3566;
acceleration = 3 - 0.000062.*velocity.^2;

subplot(3,1,1);
plot(time,velocity);
xlabel('time');
ylabel('velocity');
grid;
title('Velocity vs Time');
set(gca,'XTick',0:30:120);
set(gca,'YTick',180:10:220);

subplot(3,1,2);
plot(time,acceleration);
xlabel('time');
ylabel('acceleration');
grid;
title('Acceleration vs Time');
set(gca,'XTick',0:30:120);
set(gca,'YTick',0:5:1);

subplot(3,1,3);
plot(velocity, acceleration);
xlabel('velocity');
ylabel('acceleration');
grid;
title('Acceleration vs Velocity');
axis auto; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    相关资源
    最近更新 更多