Having issues with plotting

8 views (last 30 days)
G
G on 26 Oct 2018
Commented: madhan ravi on 26 Oct 2018
I keep getting: error using plot vectors must be the same length Not sure what I am doing wrong
I'm trying to plot this: the x-axis ranges from 0-1000 in intervals of 200 and on the y axis I am trying to plot values from a matrix that is 1row*1000columns
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000)
t=0:200:1000;
subplot(3,1,1)
plot(t,x)

Accepted Answer

Kevin Chng
Kevin Chng on 26 Oct 2018
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000)
t= 0:200:1000;
subplot(3,1,1)
plot(t,x)
for plot, length of x and y must be same. You try
length(t)
length(x)
then you will notice they are different, x has 1:1000 which is 1000 elements, but t=0:200:1000, only have 5 elements.
if you try code below, you will get the plot without error
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000)
t=1:1:1000;
subplot(3,1,1)
plot(t,x)
because now both t and x have the same length which is 1000.
  3 Comments
Kevin Chng
Kevin Chng on 26 Oct 2018
Edited: Kevin Chng on 26 Oct 2018
Sure. refer to my code below
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000)
t=1:200:1000;
subplot(3,1,1)
plot(t,x(t))
madhan ravi
madhan ravi on 26 Oct 2018
+1 @ Kevin elegant

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!