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
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
Azzi Abdelmalek 2013 年 2 月 15 日

0 投票

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
ayat 2013 年 2 月 15 日
thanks but maybe I wasn't clear enough...The curve that I have comes from bunch of numbers only.
Azzi Abdelmalek
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
ayat 2013 年 2 月 15 日
編集済み: Azzi Abdelmalek 2013 年 2 月 15 日
>> dY=diff(Y)./diff(X)
??? Undefined function or variable 'Y'.
I am getting this...when I type Y and press enter I get the values that I have stored in Y though!
Azzi Abdelmalek
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
Sean de Wolski 2013 年 2 月 15 日
whos Y
which -all Y
ayat
ayat 2013 年 2 月 15 日
yes I copy pasted the command just as mentioned here. Just to try something, I made a simple values for Y and X in the work space(x=0.1,0.2...,0.5) and y=1,2...,5) and tried this command for d(Y) by just copy pasting but it returned the same error!!
Azzi Abdelmalek
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
ayat
ayat 2013 年 2 月 15 日
編集済み: ayat 2013 年 2 月 15 日
ok this is getting ridiculous...! I just copy pasted this command you mentioned here and it still returns the error!!! Even when I do dY=diff(Y)./diff(X) now that I have X and Y in the workspace it return that damn error! can you verify this by doing it in your own matlab and tell me what do you get?
Azzi Abdelmalek
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
Wayne King 2013 年 2 月 15 日
you should report the error you are seeing. Azzi's example is correct
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 15 日
Ok. What is your comment?
ayat
ayat 2013 年 2 月 15 日
編集済み: Azzi Abdelmalek 2013 年 2 月 15 日
oh god, I typed so much and only the picture is left?! let me start again: This is my graph:
Now I want to have the change in the slope of this curve in a new curve! I thought doing the derivative would do the trick but this is the graph I got:
Which clearly isn't any good!
Azzi Abdelmalek
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
ayat 2013 年 2 月 15 日
umm, ok! lets just forget about the variation of noise graph that I got. How can I plot the change in the slope of original curve in a new graph?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 15 日
Try to plot log(y) in a log axis
ayat
ayat 2013 年 2 月 15 日
編集済み: Image Analyst 2013 年 2 月 15 日
You have to be very specific, this is literally the first time I am using matlab! Do you mean have log Y and then plot it against x?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 2 月 15 日
Maybe it's a bad idea
Image Analyst
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
ayat 2013 年 2 月 16 日
ok, here is the basic x-y I have:
So I need the change in the slope of this data plotted as a new curve. If you could give me the code that would do that I would really be grateful!

サインインしてコメントする。

カテゴリ

タグ

質問済み:

2013 年 2 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by