Having issues with plotting

조회 수: 1 (최근 30일)
G
G 2018년 10월 26일
댓글: madhan ravi 2018년 10월 26일
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)

채택된 답변

Kevin Chng
Kevin Chng 2018년 10월 26일
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
Kevin Chng
Kevin Chng 2018년 10월 26일
편집: Kevin Chng 2018년 10월 26일
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 2018년 10월 26일
+1 @ Kevin elegant

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by