How to find the difference between two vectors

조회 수: 4 (최근 30일)
vani
vani 2022년 10월 12일
댓글: dpb 2022년 10월 14일
Hello all,
My doubt is,
I have to find the difference between two vectors( for eg: y(8) and y(4) or y(6) and y(2)) and have to append the difference output also get the appended output in plot. So could anyone please tell me how to do these functions?.
y_try=[0 1e-9 0 0 0 1e-9 0 0] in this
y(1) =[0] ; y(2) = [1e-9] ; y(3) =[0] ; y(4) =[0]
y(5) =[0]; y(6) = [1e-9]; y(7) = [0] ; y(8) = [0]
  댓글 수: 3
vani
vani 2022년 10월 12일
I have to find the difference of output for each vectors (y(8) and y(4) , y(6) and y(2), y(7) and y(3), y(5) and y(1)) and append all these difference output and plot as a figure.
vani
vani 2022년 10월 13일
Thank you for your response. The difference is working and now I have problem with appending.

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

채택된 답변

dpb
dpb 2022년 10월 12일
Well, this is a guess, but it appears that maybe you have x,y data strung together in a single vector and want to separate out the two and difference -- try
y_try=[0 1e-9 0 0 0 1e-9 0 0];
d=diff(reshape(y_try,[],2),[],2);
plot(d)
Of course, with the above dataset the differences are all identically zero; this may be just owing to the particular values used as example or, it could be a complete misunderstanding of the intent of the question...
  댓글 수: 10
vani
vani 2022년 10월 14일
Thank you so much for your response. Your code helped a lot to rectify the error.
dpb
dpb 2022년 10월 14일
Glad to help where can...even though sometimes we don't have enough information to have any idea what the result means, can still at least fix syntax errors or find the correct command for the job.
If the above resolved the problem, please go ahead and "Accept" the answer if or no other reason than to let others know it's not still an outstanding issue.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by