how to plot the vectors having different length

조회 수: 35 (최근 30일)
kavya saxena
kavya saxena 2012년 10월 16일
답변: SABRINA SABRINA 2019년 4월 23일
hi all, i have two vectors one is time and other is amplitude. length of time is 140 whereas length of amplitude is double of it 279, i hv to plot time v/s amplitude but as i use plot(t,y),it gives an error that vectors should be of same length. what should i do....

답변 (5개)

Jos (10584)
Jos (10584) 2016년 2월 24일
You can use interpolation
X_known = [1 2 3 6 8 10] ;
Y_known = [2 5 6 11 18 23] ;
X_desired = 1:10
Y_desired = interp1(X_known, Y_known, X_desired)
plot(X_desired, Y_desired,'rs-', X_known, Y_known,'bo')

Matt Fig
Matt Fig 2012년 10월 16일
편집: Matt Fig 2012년 10월 16일
If you know the starting time and ending time for the amplitude, you can just make your own time vector of the correct length.
t = linspace(beginningtime,endingtime,length(y));
plot(t,y)
This assumes the y data was sampled at equal time spacings. If that is not the case, you should give more information about how you ended up with two vectors of different lengths and the relationship between t(idx) and y(idx) for a given idx.
  댓글 수: 1
kavya saxena
kavya saxena 2012년 10월 16일
hello,thanx for ur reply. actually my problem is that i hv 2 signals with same time nd i m doing cross correlation using xcorr()function. it makes my signal length double for the same time. i m not getting the cross correlation plot which having one peak value against the time interval. i m sending u what i did
t=startnode(:,1); ux1=startnode(:,2); ux2=endnode(:,2); y=xcorr(ux1,ux2); n=length(t); plot(t,y); it gives error that vector must be same length. when i did according to u it again add the two values of ux1 and ux2 and gives a signal sort of plot, not any peak value as cross correlation function gives. m i using this function correctly? plz help me..

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


Flavio Baduini
Flavio Baduini 2016년 4월 3일
편집: Flavio Baduini 2016년 4월 3일
The question is of primary importance, I'm facing the same while plotting raw and averaged sensors data.
.
ex:
raw data: y (a vector of length 1000)
averaged data: z (a vector of length 100)
.
You can define a common x-axis and plot your vectors with respect to that. I chose time and I made an average of time values for each 10 samples (10 because I'm averaging 10 values each):
.
time: t (a vector of length 1000)
time averaged: ta (a vector of length 100)
.
Now just plot the values with the same length and you'll get two graphs with the raw and averaged data, in the same plot and with the correct spacing
.
plot(t,y)
plot(ta,z)

kavya k
kavya k 2017년 5월 16일
i have to plot the graph between the lumens(different ND filters) and pixel intensity. pixel intensity of an image is of size 240*320 .like that i have to plot for 4 images. i am getting an error as vectors are of different sizes. can any one help me. i have attached the file what the code i have written. plz help me out of this.....
  댓글 수: 2
Jan
Jan 2017년 5월 16일
Please do not append a new question in the section for answers of another thread. Delete this message and open a new thread instead. Thank you.
Jan
Jan 2017년 5월 16일
편집: Jan 2017년 5월 16일
Please do not append a new question in the section for answers of another thread. Delete this message and open a new thread instead. Include a complete copy of the error message there. Thank you.

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


SABRINA SABRINA
SABRINA SABRINA 2019년 4월 23일
hi
I have a file.txt which has 20 points following x and 17 points following y with combinations E = 20 * 17 points I want to draw E in the xy plane BUT it displays error because they do not have the same dimensions

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by