plot axis based on a function found online

I found the following function:
what do I not to do to be able to save that function to my matlab and is there a way somebody else who hasen't downloaded that file is still able to see what it's doing?

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 3 月 29 日

0 投票

At the bottom of that page there is a header
Related Documents/Files:
below which there is a link for drawaxis.m . Click on that link to download the file. Put the file in a convenient location on your MATLAB path.
Anyone who wishes to execute your code will need a copy of the file. You could include it along with your code.

9 件のコメント

Locks
Locks 2013 年 3 月 29 日
I have downloaded it, but can I now execute a function with the code:
drawaxis(gca, 'x', 0, 'movelabel', 1)
and matlab automatically knows to which function this is referring to?
Walter Roberson
Walter Roberson 2013 年 3 月 29 日
It does not work on the basis of functions or individual lines: it works on the basis of axes, by examining the axes limits, which plotting automatically sets based on the range of values you plotted values over.
Locks
Locks 2013 年 3 月 29 日
I am sorry, but I do not get what I have to do after downloading the file, could you explain to me what excatly is necessary to work with this?
Walter Roberson
Walter Roberson 2013 年 3 月 29 日
Use the command
pathtool
and ensure that the directory where you stored drawaxis.m is on the MATLAB path.
Once it is, then after you have done all your other plotting for the axis you want to affect, put the command in your code
drawaxis(gca, 'x', 0, 'movelabel', 1)
Locks
Locks 2013 年 3 月 29 日
doing this, I get this error:
Error using drawaxis (line 87) Specified X crossing outside axis limits
do you have any idea why that could be?
Walter Roberson
Walter Roberson 2013 年 3 月 29 日
You did not follow the instructions to "set axis limits appropriately".
YL = get(gca, 'YLim');
YL(1) = min(0, YL(1));
YL(2) = max(0, YL(2));
set(gca, 'YLim', YL);
Note: you might find that once the above is done that you do not need to use drawaxis()
Locks
Locks 2013 年 3 月 29 日
編集済み: Walter Roberson 2013 年 3 月 30 日
I tried to insert your code, but it doesn't word, here is the full code:
x =[0:0.01:20]
y1=blsprice(x,10,0.02,0.2,0.2)-blsprice(10,10,0.02,0.2,0.2)
y2=max(x-10,0)-blsprice(10,10,0.02,0.2,0.2)
plot(x,y1,'k',x,y2)
What do I need to change?
xlabel('Stock Price at Maturity ($)');
ylabel('Gain ($)');
axis([8.5 11.5 -0.5 1]);
set(gca,'xtick',9:0.5:11.5)
y1L = get(gca, 'yLim');
y1L(1) = min(0, y1L(1));
y1L(2) = max(0, y1L(2));
set(gca, 'yLim', y1L);
annotation(gcf,'doublearrow',[0.515 0.515],[0.2 0.36])
text(10.25,-0.2,'Time value')
set(gca,'Box','off')
Walter Roberson
Walter Roberson 2013 年 3 月 30 日
Are you getting an error message? I do not have the toolbox with blsprice() in it, so I cannot test your code.
Locks
Locks 2013 年 3 月 30 日
x =[0:0.01:20]
y1=blsprice(x,10,0.02,0.2,0.2)-blsprice(10,10,0.02,0.2,0.2)
y2=max(x-10,0)-blsprice(10,10,0.02,0.2,0.2)
plot(x,y1,'k',x,y2)
xlabel('Stock Price at Maturity ($)');
ylabel('Gain ($)');
axis([8.5 11.5 -0.5 1]);
set(gca,'xtick',9:0.5:11.5)
annotation(gcf,'doublearrow',[0.515 0.515],[0.2 0.36])
text(10.25,-0.2,'Time value')
set(gca,'Box','off')
this code is perfectly working so I guess it can't be blsprice ()
could you tell me what I excatly ned to change in my code and where I have to place the new elements?

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

カテゴリ

タグ

質問済み:

2013 年 3 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by