How to plot the dervative of a curve
이전 댓글 표시
Hi, I am very new to Matlab so apologies in advance! I have two columns of numbers which I have used for plotting a simple x-y curve. Now I need to have the derivate of this curve. So it would be like dx/dy for Y axis.
댓글 수: 1
Jan
2013년 2월 15일
When you post the code (or an example code) for "I have two columns of numbers", it would be much easier to create an answer. Obviously Azzi fails to guess the names of the variables you use, and you fail to transfer his suggestion to you real application.
답변 (1개)
Azzi Abdelmalek
2013년 2월 15일
For example
X=0:0.1:10 % Your x-axis
Y=sin(X) % Your strain signal
dY=diff(Y)./diff(X)
plot(X,Y) % Your original signal
hold on
plot(X(2:end),dY,'r') %Your derivative signal
댓글 수: 19
ayat
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
Yes, It's just an example. Use your own data X and Y
dY=diff(Y)./diff(X)
plot(X,Y) % Your original signal
hold on
plot(X(2:end),dY,'r') %Your derivative signal
ayat
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
Are you sur you are using Y and not y. uppercase and lowercase letters are different in Matlab
Sean de Wolski
2013년 2월 15일
whos Y
which -all Y
ayat
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
x=0.1:0.1:0.5
y=1:5
dY=diff(Y)./diff(X)
plot(X,Y) % Your original signal
hold on
plot(X(2:end),dY,'r') %Your derivative signal
Azzi Abdelmalek
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
Now it's my mistake: x is different from X. Try again
x=0.1:0.1:0.5
y=1:5
dy=diff(y)./diff(x)
plot(x,x) % Your original signal
hold on
plot(x(2:end),dy,'r') %Your derivative signal
Wayne King
2013년 2월 15일
you should report the error you are seeing. Azzi's example is correct
Azzi Abdelmalek
2013년 2월 15일
Ok. What is your comment?
ayat
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
편집: Azzi Abdelmalek
2013년 2월 15일
These are the variation of your noise. Also, diff(y)/y is just an approximation of a derivative
ayat
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
Try to plot log(y) in a log axis
ayat
2013년 2월 15일
편집: Image Analyst
2013년 2월 15일
Azzi Abdelmalek
2013년 2월 15일
Maybe it's a bad idea
Image Analyst
2013년 2월 15일
편집: Image Analyst
2013년 2월 15일
Let's quit wasting time. ayat, upload your data somewhere - your favorite web site. Tell us the URL, and the code you used to read in the data file, so we can give you code that uses your exact data. Azzi's example was correct - you obviously changed something in it. You probably have a huge derivative because at some point(s) your curve turns almost vertical.
ayat
2013년 2월 16일
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

